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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
DemingPDCA
Helper II
Helper II

Find First Instance After a different instance

Hopefully I can explain this. I'm looking to find two things. First I need a measure that first the first Positive AFTER the first negative, then I need to find how negative did we go before we went positive?

Examples:

DemingPDCA_0-1689823421049.png

In this example - the stock out date is 7/31 (calculated as: 

CALCULATE(Min('Inventory Watch'[Due Date]), FILTER('Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative") )

I would also liked to return the first positive after the stockout date (8/4), and was is the most negative we went during that date range (-5)


Example 2:

Stock out Date = 8/1


If copy and past needed:First Positive After Stock Out = 8/4
Most Negative = -3
DemingPDCA_1-1689823581134.png

if copy paste needed

IndexDue DateRunning TotalCheckStatus
709167/5/202312Positive
709177/12/202311Positive
709187/18/202310Positive
709197/21/20239Positive
709207/28/20238Positive
709218/1/2023-2Negative
709228/3/2023-3Negative
709238/4/20232Positive
709248/10/20231Positive
709258/18/20234Positive
709268/18/20233Positive
1 ACCEPTED SOLUTION
rubayatyasmin
Community Champion
Community Champion

Hi, @DemingPDCA 

 

In this case, you can use a similar approach as the one you used for finding the stock out date.

  1. To find the first Positive AFTER the first negative, you need to get the Min Due Date where CheckStatus is Positive, but only from the rows after the first row where CheckStatus is Negative. example
CALCULATE (
    MIN ( 'Inventory Watch'[Due Date] ),
    FILTER (
        ALL ( 'Inventory Watch' ),
        'Inventory Watch'[Due Date] > CALCULATE (
            MIN ( 'Inventory Watch'[Due Date] ),
            FILTER ( 'Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative" )
        )
            && 'Inventory Watch'[CheckStatus] = "Positive"
    )
)

 

To find the most negative value between the first Negative and the next Positive, you would use a formula like:

 

CALCULATE (
    MIN ( 'Inventory Watch'[Running Total] ),
    FILTER (
        ALL ( 'Inventory Watch' ),
        'Inventory Watch'[Due Date] >= CALCULATE (
            MIN ( 'Inventory Watch'[Due Date] ),
            FILTER ( 'Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative" )
        )
            && 'Inventory Watch'[Due Date] <= CALCULATE (
                MIN ( 'Inventory Watch'[Due Date] ),
                FILTER (
                    ALL ( 'Inventory Watch' ),
                    'Inventory Watch'[Due Date] > CALCULATE (
                        MIN ( 'Inventory Watch'[Due Date] ),
                        FILTER ( 'Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative" )
                    )
                        && 'Inventory Watch'[CheckStatus] = "Positive"
                )
            )
    )
)

 

These DAX formulae will help you find the first positive date after the first negative one, and the minimum (most negative) 'Running Total' value between the first negative date and the next positive one.

 

note: youmight need some adjustment

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

3 REPLIES 3
DemingPDCA
Helper II
Helper II

You - have just saved me SO MUCH time and frustration!!! I cannot thank you enough!!!

DemingPDCA_0-1689856866502.png

 

Happy to help. 

 

Appreciate the kudos. 👍


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


rubayatyasmin
Community Champion
Community Champion

Hi, @DemingPDCA 

 

In this case, you can use a similar approach as the one you used for finding the stock out date.

  1. To find the first Positive AFTER the first negative, you need to get the Min Due Date where CheckStatus is Positive, but only from the rows after the first row where CheckStatus is Negative. example
CALCULATE (
    MIN ( 'Inventory Watch'[Due Date] ),
    FILTER (
        ALL ( 'Inventory Watch' ),
        'Inventory Watch'[Due Date] > CALCULATE (
            MIN ( 'Inventory Watch'[Due Date] ),
            FILTER ( 'Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative" )
        )
            && 'Inventory Watch'[CheckStatus] = "Positive"
    )
)

 

To find the most negative value between the first Negative and the next Positive, you would use a formula like:

 

CALCULATE (
    MIN ( 'Inventory Watch'[Running Total] ),
    FILTER (
        ALL ( 'Inventory Watch' ),
        'Inventory Watch'[Due Date] >= CALCULATE (
            MIN ( 'Inventory Watch'[Due Date] ),
            FILTER ( 'Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative" )
        )
            && 'Inventory Watch'[Due Date] <= CALCULATE (
                MIN ( 'Inventory Watch'[Due Date] ),
                FILTER (
                    ALL ( 'Inventory Watch' ),
                    'Inventory Watch'[Due Date] > CALCULATE (
                        MIN ( 'Inventory Watch'[Due Date] ),
                        FILTER ( 'Inventory Watch', 'Inventory Watch'[CheckStatus] = "Negative" )
                    )
                        && 'Inventory Watch'[CheckStatus] = "Positive"
                )
            )
    )
)

 

These DAX formulae will help you find the first positive date after the first negative one, and the minimum (most negative) 'Running Total' value between the first negative date and the next positive one.

 

note: youmight need some adjustment

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

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

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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