Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hi Everyone,
I have a column chart in Power BI which shows statewise sales. I have a slicer for states. The requirement is, if the user selects only one state in the slicer, the table should show citywise sales for that respective state. If the user selects more than one state in the slicer, I want to show statewise sales.
I tried using the following DAX formula:
Column = IF(COUNTROWS(VALUES(Orders[State])) = 1, VALUES(Orders[City]), VALUES(Orders[State]))
However, I'm getting an error message:
MdxScript(Model) (4, 76) Calculation error in measure 'DAX Measures'[Column]: A table of multiple values was supplied where a single value was expected.
Can someone please help me with this? Any help would be appreciated.
Thanks!
Solved! Go to Solution.
Hi @wickkey
I've attached an example of how this can be done. It's an interesting application of field parameters.
Field parameters are a preview feature so need to be enabled in the "Preview features" settings.
Does this work in your report?
State/City Filter =
-- SingleState = 1 if a single state has been selected on slicer, otherwise 0
VAR SingleState =
INT (
CALCULATE ( HASONEVALUE ( Orders[State] ), ALLSELECTED () )
)
-- CityOption = 1 if the current Field Parameter option = City, otherwise 0
VAR CityOption =
INT ( MIN ( 'State/City'[State/City] ) = "City" )
RETURN
-- Return 1 if SingleState & CityOption both = 1 (display city), or if SingleState & CityOption both = 0 (display state)
INT ( SingleState = CityOption )
I really appreciate your help. Your response was exactly what I needed. Thank you for taking the time to help me out! 😊
Hi @wickkey
I've attached an example of how this can be done. It's an interesting application of field parameters.
Field parameters are a preview feature so need to be enabled in the "Preview features" settings.
Does this work in your report?
State/City Filter =
-- SingleState = 1 if a single state has been selected on slicer, otherwise 0
VAR SingleState =
INT (
CALCULATE ( HASONEVALUE ( Orders[State] ), ALLSELECTED () )
)
-- CityOption = 1 if the current Field Parameter option = City, otherwise 0
VAR CityOption =
INT ( MIN ( 'State/City'[State/City] ) = "City" )
RETURN
-- Return 1 if SingleState & CityOption both = 1 (display city), or if SingleState & CityOption both = 0 (display state)
INT ( SingleState = CityOption )
User | Count |
---|---|
93 | |
83 | |
77 | |
73 | |
66 |
User | Count |
---|---|
115 | |
104 | |
93 | |
64 | |
61 |