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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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]
    )

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]
    )

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors