Sub topic 9
Letting users set thresholds with a parameter table
This chapter assumes you can write basic DAX measures, you have built the [Variance %] and [Variance Color] measures from earlier chapters, and you know how to apply a measure with Format by field value. Here you replace the hard-coded 5% green threshold with a value the report reader picks in a slicer.
Why parameterize a threshold
A threshold written inside a measure, such as v >= 0.05, can only be changed by someone who edits the model. Different readers often want different cutoffs. A regional manager may call 3% above target "good," while finance may require 8%. A parameter table lets each reader choose the cutoff without touching DAX.
The idea has three parts:
- A small table holds the candidate values.
- A slicer on that table lets the reader pick one.
- A measure reads the selection and the color measure uses it.
Build the parameter table
Create a calculated table with GENERATESERIES. It returns a single-column table named Value.
Threshold = GENERATESERIES ( 0, 0.2, 0.01 )This produces 21 rows: 0, 0.01, 0.02, up to 0.2. Select the Value column and set its format to percentage so the slicer shows "5%" instead of "0.05".
Do not create a relationship between Threshold and any other table. The table exists only to hold the reader's choice. A relationship would filter your fact tables by the selection, which is not what you want.
Read the selection with SELECTEDVALUE
Add a measure that returns the chosen value:
Green Threshold =
SELECTEDVALUE ( Threshold[Value], 0.05 )SELECTEDVALUE returns the value when exactly one row of Threshold[Value] is visible in the current filter context. If nothing is selected, or if several values are selected, it returns the second argument. Here that default is 0.05, so the report behaves like the earlier version until the reader makes a choice.
Use the measure in the color logic
Copy the color measure from the SWITCH chapter and replace the literal with a variable that reads the parameter:
Variance Color (Dynamic) =
VAR v = [Variance %]
VAR limit = [Green Threshold]
RETURN
SWITCH (
TRUE (),
ISBLANK ( v ), BLANK (),
v >= limit, "#2E7D32",
v >= 0, "#F9A825",
"#C62828"
)Apply it with Format by field value, as before. When the reader moves the slicer to 8%, cells with a variance between 5% and 8% change from green to amber.
Common errors
- The slicer does nothing. Check that the slicer uses
Threshold[Value], not a column from another table. - The threshold always equals 5%. The slicer probably allows multiple selections, or none, so
SELECTEDVALUEfalls back to its default. Set the slicer to single select. - Other visuals change when the slicer moves. A relationship exists between
Thresholdand another table. Delete it. - The slicer is hidden from readers but the default still applies. This is fine when you want a fixed default. If you want users to choose, keep the slicer visible.
Design considerations
Keep the step size sensible. A step of 0.01 gives 21 choices, which fits a dropdown slicer. A step of 0.001 gives hundreds, and a list slicer becomes unwieldy.
Label the slicer with a clear title such as "Green if variance is at least". Readers otherwise cannot tell what the number controls. Because the cutoff changes the meaning of the colors, consider showing the current value in a card or in the visual title so a screenshot still explains itself.
Exercise
A report has the Threshold slicer set to allow multiple selections. A reader selects 3% and 6% together. Which green cutoff does [Variance Color (Dynamic)] use, and why?
Show answer
It uses 5% (0.05). SELECTEDVALUE returns its default only when exactly one value is not visible, so with two values selected it returns the default argument of 0.05. To avoid this, set the slicer to single select.