Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
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 ?
State | City | Sales |
California | San diego | 23 |
California | Los Angeles | 55 |
California | San Francisco | 35 |
Florida | Miami | 32 |
Florida | Orlando | 48 |
Florida | Jacksonville | 44 |
Georgia | Atlanta | 46 |
Georgia | Augusta | 31 |
Georgia | Savannah | 53 |
State | Rank | |
Georgia | 1 | |
Florida | 2 | |
California | 3 | |
City | Rank | |
Los Angeles | 1 | |
Savannah | 2 | |
Orlando | 3 | |
Atlanta | 4 | |
Jacksonville | 5 | |
San Francisco | 6 | |
Miami | 7 | |
Augusta | 8 | |
San diego | 9 |
Hi,
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] ) ) )
)
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Thank you.
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.
Regards.
Hi,
Thank you for your feedback.
Please check the below picture and the attached pbix file whether one of two visualizations is what you are looking for.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi again,
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 ?
Regards
Hi,
Thank you for your message.
I assume your data model looks something like below.
If my assumption is wrong, please provide your sample pbix file's link.
Please check the below picture and the attached pbix file whether it suits your requirement.
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
90 | |
88 | |
83 | |
64 | |
49 |
User | Count |
---|---|
126 | |
110 | |
87 | |
70 | |
66 |