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

View all the Fabric Data Days sessions on demand. View schedule

Reply
Anonymous
Not applicable

Measure for optimistic/pessimistic scenario

Hello,

In my data model I created a measure to sum the purchase for each week number for past years. I'm using a unrelated date table to acheive this because I have many other tables from many sources in my original model. I also created a measure to rank the purchase by week number.
Now for the future date I need to calculate the optimistic and pessimistic scenario from past years. I actually have about 3 years of data but I will have many more soon. For optmistic scenario I need to calculate the average of the best 2 years (rank 1 and 2). For pessimistic , it's the 2 worst years (of 5 last years).

https://www.dropbox.com/s/igaz4zqam5b7pbu/Test_purchase.pbix?dl=0 

With these data, the expected result for 2022, week #49 should be:
Optimistic = 26703 (average of rank 1 & 2)
Pessimistic = 19585 (average of rank 2 & 3)

FRG_0-1649355226596.png
How can I acheive this?

Thank you!

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Thank you for providing the pbix.  Unfortunately your sample data has too many holes to be useful.

 

lbendlin_0-1649468056552.png

Rank 3 is missing from most weeks, for example.

 

Anyway, here is a proposal based on your data  (note that I had to modify your data model.  I would also strongly recommend you should not use the built in date hierarchies)

 

Opt = 
var wt = year(today())*100+weeknum(TODAY(),1)
return  if (SELECTEDVALUE(DimDate[Year/week])<wt,BLANK(),
 var w= SELECTEDVALUE(DimDate[#Week])
 var a= SUMMARIZE(FILTER(ALL(DimDate),DimDate[#Week]=w),DimDate[Date].[Année],"Purch",[Purchase])
  var b = topn(2,a,[Purch],DESC)
 return AVERAGEX(b,[Purch]))

 

pbix attached.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

Thank you for providing the pbix.  Unfortunately your sample data has too many holes to be useful.

 

lbendlin_0-1649468056552.png

Rank 3 is missing from most weeks, for example.

 

Anyway, here is a proposal based on your data  (note that I had to modify your data model.  I would also strongly recommend you should not use the built in date hierarchies)

 

Opt = 
var wt = year(today())*100+weeknum(TODAY(),1)
return  if (SELECTEDVALUE(DimDate[Year/week])<wt,BLANK(),
 var w= SELECTEDVALUE(DimDate[#Week])
 var a= SUMMARIZE(FILTER(ALL(DimDate),DimDate[#Week]=w),DimDate[Date].[Année],"Purch",[Purchase])
  var b = topn(2,a,[Purch],DESC)
 return AVERAGEX(b,[Purch]))

 

pbix attached.

Anonymous
Not applicable

Hello @lbendlin ,

Is it possible to sum de opt measure like this?

FRG_2-1654264038221.png

 

Thank you

 

yes, you can use a quick measure to add a cumulative sum.

Anonymous
Not applicable

Thanks a lot! It helps me to go forward!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors