www.antaresanalytics.net Open in urlscan Pro
151.101.1.84  Public Scan

Submitted URL: http://www.antaresanalytics.net/post/2018/09/11/power-bi-creating-user-input-variables
Effective URL: https://www.antaresanalytics.net/post/2018/09/11/power-bi-creating-user-input-variables
Submission: On May 03 via manual from AT — Scanned from DE

Form analysis 0 forms found in the DOM

Text Content

top of page
Skip to Main Content



THE ANTARES ALIEN


POWER BI   |  GAME DEVELOPMENT

 * About

 * Services

 * Power BI Blog

 * Game Projects

 * Power BI Projects

 * Power BI Guide

 * Privacy Policy

 * Game Releases Over Time

 * More...


Use tab to navigate through the menu items.


THE ANTARES ALIEN


POWER BI   |  GAME DEVELOPMENT

 * All Posts
 * Indie Development
 * Power BI
 * Power Query
 * Dashboard Design
 * More

Search

 * Brent Jones
 * 
 * * Sep 14, 2018




2 EASY STEPS TO CREATING USER INPUT VARIABLES WITH POWER BI

Updated: Oct 9, 2022















CREATING THE USER INPUT VARIABLE



Inserting input variables is a bit unintuitive in Power BI, but hopefully this
article will clear it up. There are basically two steps:








1. CREATE A NEW "WHAT IF" PARAMETER UNDER THE MODELING TAB:









Clicking this button will bring up a new window with several input options.
















2. ENTER THE RANGE OF NUMBERS AND THE NUMBER OF STEPS IN BETWEEN:









 * Name: This is the name of your parameter (input variable).

 * Data Type: This defines the type of variable. Whole number, Decimal number or
   Fixed decimal number.

 * Minimum & Maximum: These are the starting and ending numbers for your
   variable (think of it like a range of valid inputs).

 * Increment: This represents the increment between your minimum and maximum
   values. This will affect how many values can be selected as an input.





After you have your range of numbers (values entered for Minimum, Maximum) and
the increment, click OK and Power BI will insert a new table for you in your DAX
model. This is your table of valid input options for your users.












EXAMPLE USE CASES FOR RANGES AND INCREMENTS



If you chose 0 as your minimum, 2 as your maximum, and 1 as your increment, you
will get a table of values for:



 * 0

 * 1

 * 2





If you chose a 0 min, 2 max, and 0.5 as your increment, you will get:



 * 0

 * 0.5

 * 1.0

 * 1.5

 * 2.0





NOTE: If you do chose a decimal number as your increment, be sure to have a
leading zero. Otherwise, Power BI might not let you continue with the parameter.
For example, you need to enter 0.5, instead of .5.















ADDING THE INPUT BOX



If you chose to Add a slicer to the page, it should have also inserted a single
value slider filter accordingly.








 




Alien Tip: Notice how there is only one slider (the little circle handle). This
allows us to limit the user input to a single value, as opposed to having
'between' or 'greater than' values. By using a "what if" parameter, we get this
functionality. If we used a normal table, we would be unable to get this single
value slider. On the other hand, we are unable to get a multiple value slider
with a what if parameter. Keep these points in mind.
































A DEEPER LOOK



Checking out the DAX formula for the Parameter table, we can see that it's
simple a GENERATESERIES() function. This has three variables to pass in; the
minimum, maximum, and the iteration. We can easily modify these values to
increase or decrease the number of options we want our users to have. At the
same time, this creates a great way to automatically validate our users inputs.
For example, we don't want them inserting the string 'ten' instead of a numeric
'10'.







We are not limited to hard coded values either. If we want a list of values from
1 to the number of records we have in the data set, we can use COUNTA() for the
maximum parameter. This will result in a dynamic user input variable. For
example:







=GENERATESERIES( 1, COUNTA(MyDataSet[ID]), 1)







QUESTION: "AM I LIMITED TO JUST NUMERIC INPUTS?"







With a small amount of innovation, we can create other types. Though, we need to
apply some extra steps depending on what you are looking for.
















HOW ABOUT A DATE INPUT?



We can accomplish this by using the numeric serial values that all dates use.
For example todays date (as of writing) is 9/12/2018. The serial value for this
is 43355. Adding 1 to this number gives us tomorrows date, 9/13/2018, or 43356.
Knowing this, we can change our input variables for the GENERATESERIES()
function to:










=GENERATESERIES( 43355, 43370, 1)










43370 is the last date of 2018, 12/31/2018. Of course, doing it this way would
limit us to a single date. Instead, we can use DAX date functions like TODAY()
and DATE() to get a dynamic result:










=GENERATESERIES( Value(Today()), 
  Value(Date(Year(Today()), 12, 31)), 1)










Why am I using Value()? If we don't, the value is returned as a date type value.
It may be a bug, but it messes up the single value slicer and ends up putting
two input boxes, and effectively breaking the parameter:

















So we want to use Value() in our parameter so our slider works.













"But I don't want that number to show on my input box. It looks ugly!"



You're right. Unfortunately we can't manually change the data type either,
because it'll break the parameter with the same issues as above. However, if you
don't mind your users just using the slider as opposed to the input box, you can
'hide it' by creating a card, filling in the background with white, and lay it
over the input box. Something like this:









It may not be the most graceful, but it gets the job done.







In the dashboard at the very beginning of this article, I created 3 separate
"what if" parameters to get the desired result of computing the time it takes
for two trains to meet at a variable distance and speeds. You can create as many
as you'd like, so go crazy with it!







Check out the Microsoft documentation to see some more examples. Also, if you'd
like to ready about how to use these parameters with Python, see my blog about
Zooming into the Mandelbrot fractal with Power BI.






 


If you are looking to improve your DAX skills, I would recommend Supercharge
Power BI by Matt Allington:








#PowerBI #Tips #parameter #User #Input #variables #DAX #dynamic #Whatif



 * Power BI






 * 
 * 
 * 



An Alternative to Calculation Groups in Power BI

9

The Best Guide to FILTER() and CALCULATETABLE() Differences

378

Using a Custom Function Within List.Generate()

96






Follow

 * 
 * 
 * 



©2021 BY ANTARES ANLYTICS. PROUDLY CREATED WITH WIX.COM


bottom of page