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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
penumatsas
Regular Visitor

How to find related next record after last occurrence of a negative value in a table

 

I have table as shown below and i need to find date for a given Region which has backlog as positive number after the last record which has negative backlog for that  particular region.

 

RegionDateBacklog
A5/1/201910
A5/2/2019-1
A5/3/2019100
A5/6/2019-2
A5/8/2019200
A5/9/2019100
B5/1/201920
B5/2/2019-10
B5/3/201930
B5/6/201940
B5/8/201930
B5/9/201940

 

Result Needed:

 

RegionTarget Date
A5/8/2019
B5/3/2019

 

How to accomplish it?

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@penumatsas 

 

This mEASURE works with your sample data

 

Measure =
VAR LastNegative =
    MINX ( TOPN ( 1, FILTER ( Table1, [Backlog] < 0 ), [Date], DESC ), [Date] )
RETURN
    MINX (
        TOPN (
            1,
            FILTER ( Table1, [Backlog] >= 0 && [Date] > LastNegative ),
            [Date], ASC
        ),
        [Date]
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

1 REPLY 1
Zubair_Muhammad
Community Champion
Community Champion

@penumatsas 

 

This mEASURE works with your sample data

 

Measure =
VAR LastNegative =
    MINX ( TOPN ( 1, FILTER ( Table1, [Backlog] < 0 ), [Date], DESC ), [Date] )
RETURN
    MINX (
        TOPN (
            1,
            FILTER ( Table1, [Backlog] >= 0 && [Date] > LastNegative ),
            [Date], ASC
        ),
        [Date]
    )

Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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