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

Get 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

Reply
Newby
Frequent Visitor

Minimum value of a measure

Hi, 

 

I have a number of measures:

 

3m Rolling Return calculates the 3m rolling return of a stock from a database of stocks:

3m Rolling Return = if(CALCULATE(countx(FILTER(stocks,stocks[recorddate]<=max(stocks[recorddate])),stocks[recorddate]),DATESINPERIOD(stocks[recorddate],max(stocks[recorddate]),-3,MONTH))=3,calculate(productx(stocks,stocks[monthlyreturn]+1)-1,DATESINPERIOD(stocks[recorddate],max(stocks[recorddate]),-3,MONTH)),BLANK())

 

 

3m Rolling Rank calculates the rank of that stock in the universe in a particular month:

3m Rolling Rank = if(not(ISBLANK([3m Rolling Return])),rankx(filter(all(stocks[stockname]),not(isblank([3m Rolling Return]))),[3m Rolling Return]))

 

 

3m Rolling Quartile calculates the quartile based on the rank:

3m Rolling Quartile = if(isblank([3m Rolling Return]),blank(),roundup([3m Rolling Rank]*4/countx(all(stocks[stockname]),[3m Rolling Return]),0))

 

 

I would like to calculate the minimum return that would still be in the top quartile each month. I have created the following measure:

3m min return = if(isblank([3m Rolling Return]),blank(),minx(allselected(stocks[stockname]),[3m Rolling Return]))

 

 

which works when the filter of Quartile=1 is applied in a table (stocks in the top quartile would display the correct minimum). However, when trying to plot this on a line chart, each stock would create its own line instead of showing only one line (I understand why this is happening):Newby_0-1629735682359.png

 

 

I tried to calculate an average of the measure:

3m average min = averagex(all(stocks[recorddate]),[3m min return])

 

 

However, this returns an empty table/visualisation when selecting recorddate and 3m average min. 

 

Any suggestions?

 

Many thanks in advance.

2 REPLIES 2
Greg_Deckler
Super User
Super User

@Newby This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.



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...

Thanks for the quick response, Greg, @Greg_Deckler 

Unfortunately, this still does not work - it gives an empty measure. 

The report can be accessed here: Example.pbix 

A screenshot of the report is below:

Screenshot 2021-08-25 173235.png

The expected output is:

Screenshot 2021-08-25 173402.png

I am getting the required output by exporting to Excel and then either using VLOOKUP or AVERAGEIF with the date as criteria. 

Any help will be much appreciated!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.