Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

Usings a Calculated Measure to Filter in a DAX Formula

Hello,

 

My objected is two parts (1) Calculate a dynamic ranking for a basic matrix (2) Create individual measures that return the name and profit for a specific rank (e.g. rank 2).

 

(1) Created Dynamic ranking calculated measure with following equation:

 

Product Profit Rank = RANKX(ALLSELECTED(Orders[Product Name]),CALCULATE(SUM(Orders[Profit])),,DESC)
 
Annotation 2020-09-02 111802.png

 

As you can see, it worked. And as I change the filters on the page, it dynamically adjusts.
 
(2) Attempted to create individual measures that highlight a specific rank, but am having issues. I would like a measure that returns the name of 'n' ranked product and a second that returns the profit of 'n' ranked product. Here are the DAX calculatons I think should work, but they are not. It seems that the filter portion is what is having issues, so just the first nonblank is returned or the profit for all products. Your help would be apprecaited. Thanks!
 
Rank 2 Product Name = CALCULATE(FIRSTNONBLANK(Orders[Product Name],1),FILTER(Orders, [Product Profit Rank] = 1))
 
Rank 2 Product Profit = CALCULATE(SUM(Orders[Profit),FILTER(Orders, [Product Profit Rank] = 1))
3 REPLIES 3
Greg_Deckler
Super User
Super User

@Anonymous - See if this helps. https://community.powerbi.com/t5/Quick-Measures-Gallery/To-Bleep-with-RANKX/m-p/1042520#M452

 

If not, Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@amitchandak 

 

Thanks for that information. In this case it is not exactly what I am looking for since I am looking to isolate just a single rank, rather than a TopN; I am hoping to adjust my formulas in (2) to figure out how to filter with a calculated measure. My formulas should work, so I am confused why they are not.  

amitchandak
Super User
Super User

@Anonymous , refer my rank

City Rank = RANKX(all(Geography[City]),[Sales])

 

filters I tried

Rank Top 10= CALCULATE(if([City Rank]<=10,[Sales],BLANK()) ,VALUES(Geography[City]))
Rank Top 10 1 = sumx(VALUES(Geography[City]),if([City Rank]<=10,[Sales],BLANK()) )
Top 10 City Rank = CALCULATE([Sales],TOPN(10,all(Geography[City]),[Sales],DESC),VALUES(Geography[City Id]))
Rank 2nd top = sumx(filter(VALUES(Geography[City]),[City Rank]=2),[Sales] )

 

https://databear.com/power-bi-dax-topn-function/

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.