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
tharaujo85
Frequent Visitor

Create a Measure which compares a measure with a static table of thresholds

Hello!

I want to Create a Measure which compares a measure (PlanCob) with a static table of thresholds and returns a constant (5 i.ex.) on the selected date when it crosses one of the thresholds, as it follows:

tharaujo85_0-1697578492568.png

 

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @tharaujo85 

1.You can create a index measure first

Index = RANKX(ALLSELECTED('Table'),CALCULATE(MAX([dat_data])),,ASC))

 2.Then create the following measure

Measure = var _inde=[Index]
var a=MINX(FILTER(ALLSELECTED('Table'),[PlanCob]=SELECTEDVALUE('Table'[PlanCob])),[dat_data])
var b=MINX(FILTER(ALLSELECTED('Table (2)'),[thresholds]>SELECTEDVALUE('Table'[PlanCob])),[thresholds])
var c=MAXX(FILTER(ALLSELECTED('Table'),[Index]=_inde-1),[PlanCob])
var d=MINX(FILTER(ALLSELECTED('Table (2)'),[thresholds]>c),[thresholds])
return IF(SELECTEDVALUE('Table'[dat_data])=a&&b<>d&&ISBLANK(b)=FALSE(),5)

Output

vxinruzhumsft_0-1697697400605.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

5 REPLIES 5
v-xinruzhu-msft
Community Support
Community Support

Hi @tharaujo85 

1.You can create a index measure first

Index = RANKX(ALLSELECTED('Table'),CALCULATE(MAX([dat_data])),,ASC))

 2.Then create the following measure

Measure = var _inde=[Index]
var a=MINX(FILTER(ALLSELECTED('Table'),[PlanCob]=SELECTEDVALUE('Table'[PlanCob])),[dat_data])
var b=MINX(FILTER(ALLSELECTED('Table (2)'),[thresholds]>SELECTEDVALUE('Table'[PlanCob])),[thresholds])
var c=MAXX(FILTER(ALLSELECTED('Table'),[Index]=_inde-1),[PlanCob])
var d=MINX(FILTER(ALLSELECTED('Table (2)'),[thresholds]>c),[thresholds])
return IF(SELECTEDVALUE('Table'[dat_data])=a&&b<>d&&ISBLANK(b)=FALSE(),5)

Output

vxinruzhumsft_0-1697697400605.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Just didn't understood why create the 'a' variable. I commented it and it worked ok. Do you see any case that it will be necessary?

Thank you @v-xinruzhu-msft !!!

Very interesting manner to solve it. Took me sometime but understood it.

amitchandak
Super User
Super User

@tharaujo85 , If thresholds table has date, you can join both then on common date dim and pull the measure from both table together 

 

or Have a measure like

calculate(Sum(thresholds[Value]), filter(thresholds, thresholds [Date] = max(Table[Date]) ) )

 

You can also consider treatas

https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax/

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak ! Thanks for your reply.

It doesn't have dates....it's a simple table to mark when inventory crosses theses thresholds of monthly coverage.
I believe the measure has to read the PlanCob at the selected day and PlanCob the day before and check if the former is smaller than one of the thresholds and the latter is greater.

 

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! Prices go up Feb. 11th.

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.

Jan NL Carousel

Fabric Community Update - January 2025

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