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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Return the closest DATE evaluating a condition on a measure

Hello,

 

I am looking for to return the closest date for which a measure that I evaluate is below zero :

I evaluate the evolution of a stock level for different materials and I wish to return the first date on which one of the materials is with a stock value below zero. I tried to use FIRSTDATE and LASTDATE but without success : 

 

ShortageDate = CALCULATE(FIRSTDATE(DateTable[Date]), FILTER(DateTable, [Real Stock] < 0))

With this expression it returns the date on which the aggregation of all the stocks for the different materials are going below zero. 

 

Thanks in advance for your help

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

Hi, @Anonymous 

 

You need to put the material column as a slicer,and try this measure:

ShortageDate =
MINX (
    FILTER (
        ALL ( DateTable ),
        [Real Stock] < 0
            && [Material] = SELECTEDVALUE ( Material )
    ),
    [Date]
)

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

2 REPLIES 2
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

You need to put the material column as a slicer,and try this measure:

ShortageDate =
MINX (
    FILTER (
        ALL ( DateTable ),
        [Real Stock] < 0
            && [Material] = SELECTEDVALUE ( Material )
    ),
    [Date]
)

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

sayaliredij
Solution Sage
Solution Sage

It would be better if i could see how data looks like. 

 

But I would imagine this measure 

 

Measure = CALCULATE(MAX('Table'[Current Date]), FILTER('Table','Table'[Stock] = 0))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.