The right below data by State and by City sales needs to be ranked based on sales....the tricky part is that I would like to rank this within 1 MATRIX style table visual (not in 2 separate tables), so I can toggle/switch between both variables to produce the ranking by state and by city as you can see further below (this is called ranking by multiple level of hierarchy)
I know that to rank by state (for example), you need to write something like this:
Does anybody know the DAX to accomplish ranking by state and by city ?
I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.
Rank measure: = SWITCH ( TRUE (), ISINSCOPE ( Data[City] ), RANKX ( ALL ( Data[City] ), CALCULATE ( SUM ( Data[Sales] ) ) ), ISINSCOPE ( Data[State] ), RANKX ( ALL ( Data[State] ), CALCULATE ( SUM ( Data[Sales] ) ) ) )
I was looking to do that within 1 Matrix style table, not in 2 separate tables....I believe it is called "ranking by multiply hierarchy levels" in a table.
I believe you have to use VAR in your DAX in combination with something like this: RANKX(ALLSELECTED(table [State]), calculate(sum[sales]).
Please let me know if you know the solution.
The sample you provided works perfectly, but it doesn't work with my data.
Could it be because the location (state and city) are in a separate table I joined with the sales table ?