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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.