Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello community,
I've found some similar issues searching the forum, but nothing quite like this situation.
Context: I got a table with data about vaccines per State, budgets, etc.
I want to show a card with a dynamic message to the user, depending on how many options (States) he selects, like this: "Hi! You are currently viewing the state X", or "Hi! You are currently viewing the states X and Y", or "Hi! You are currenty viewing multiple states"
So I got something like this:
VAR number_of_selections = COUNTROWS(VALUES('Table'[States]))
VAR none_selected = "Hi! You are viewing " & FIRSTNOBLANK('Table'[States], TRUE()) //this one shows the first State in case none is selected
VAR one_selected = "Hi! You are viewing " & SELECTEDVALUE('Table'[States])
VAR two_selected = "Hi! You are viewing " & CONCATENATEX(VALUES('Table'[States]), [States], ",")
VAR multiple_selected = "Hi! You are viewing multiple States"
RETURN
SWITCH(
TRUE(),
number_of_selections = 2, two_selected,
ISBLANK(SELECTEDVALUE('Table'[States])), none_selected,
number_of_selections = 1, one_selected,
number_of_selections >2, multiple_selected
)
The problem is the function won't return all the conditions, the one I marked in blue does not return at all. Whenever I select >2 values, 3 for example, the message shows only the first value selected. Also I had to bring the statement in green to the top, otherwise it wouldn't show up.
Any advice? Thanks in advance!
Solved! Go to Solution.
Hi @RodrigoMachado ,
This problem occurs because your later judgment has been overwritten by the previous one, so no data will appear. You can change dax to try as follows:
VAR number_of_selections = COUNTROWS(VALUES('Table'[States]))
VAR none_selected = "Hi! You are viewing " & FIRSTNOBLANK('Table'[States], TRUE()) //this one shows the first State in case none is selected
VAR one_selected = "Hi! You are viewing " & SELECTEDVALUE('Table'[States])
VAR two_selected = "Hi! You are viewing " & CONCATENATEX(VALUES('Table'[States]), [States], ",")
VAR multiple_selected = "Hi! You are viewing multiple States"
RETURN
SWITCH(
TRUE(),
ISBLANK(SELECTEDVALUE('Table'[States])), none_selected,
number_of_selections >2, multiple_selected,
number_of_selections = 2, two_selected,
number_of_selections = 1, one_selected,
)
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @RodrigoMachado ,
This problem occurs because your later judgment has been overwritten by the previous one, so no data will appear. You can change dax to try as follows:
VAR number_of_selections = COUNTROWS(VALUES('Table'[States]))
VAR none_selected = "Hi! You are viewing " & FIRSTNOBLANK('Table'[States], TRUE()) //this one shows the first State in case none is selected
VAR one_selected = "Hi! You are viewing " & SELECTEDVALUE('Table'[States])
VAR two_selected = "Hi! You are viewing " & CONCATENATEX(VALUES('Table'[States]), [States], ",")
VAR multiple_selected = "Hi! You are viewing multiple States"
RETURN
SWITCH(
TRUE(),
ISBLANK(SELECTEDVALUE('Table'[States])), none_selected,
number_of_selections >2, multiple_selected,
number_of_selections = 2, two_selected,
number_of_selections = 1, one_selected,
)
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @RodrigoMachado ,
Try with if condition like this..
Measure =
VAR number_of_selections = COUNTROWS(VALUES('Table'[States]))
VAR none_selected = "Hi! You are viewing " & FIRSTNOBLANK('Table'[States], TRUE()) //this one shows the first State in case none is selected
VAR one_selected = "Hi! You are viewing " & SELECTEDVALUE('Table'[States])
VAR two_selected = "Hi! You are viewing " & CONCATENATEX(VALUES('Table'[States]), [States], ",")
VAR multiple_selected = "Hi! You are viewing multiple States"
RETURN
IF (
number_of_selections = 2,
two_selected,
IF (
ISBLANK ( SELECTEDVALUE ( 'Table'[States] ) ),
none_selected,
IF (
number_of_selections = 1,
one_selected,
IF ( number_of_selections > 2, multiple_selected )
)
)
)
If this works, kindly mark it as a solution. Appreciate with kuddos.
Thanks @Angith_Nair ! The same problem still occurs, when I select 3 values for example, I get only the name of the first State. So weird... In my data modeling I am using a many to many relationship, I wonder if that's intefering in the measure.
User | Count |
---|---|
101 | |
90 | |
78 | |
70 | |
69 |
User | Count |
---|---|
110 | |
96 | |
95 | |
74 | |
71 |