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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
cristianj
Helper IV
Helper IV

get next value in a table group by and having conditions

Hello, I have the next table :

idclientidstatusnext 3 state id
id1113
id1223
id13312
id141812
id2517
id2627
id273 
id3819
id393 
id310211
id3113 
id1123 
id1131 
id11418 

i want to find a formula to give me the next 3 stateid in which i find the next id for idclient where status=3. Thank you

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could create a calculated column like

next 3 state id =
VAR currentClient = 'Table'[idclient]
VAR currentID = 'Table'[ID]
RETURN
    SELECTCOLUMNS (
        TOPN (
            1,
            FILTER (
                ALL ( 'Table' ),
                'Table'[idclient] = currentClient
                    && 'Table'[status] = 3
                    && 'Table'[id] > currentID
            ),
            'Table'[id], ASC
        ),
        "@val", 'Table'[id]
    )

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You could create a calculated column like

next 3 state id =
VAR currentClient = 'Table'[idclient]
VAR currentID = 'Table'[ID]
RETURN
    SELECTCOLUMNS (
        TOPN (
            1,
            FILTER (
                ALL ( 'Table' ),
                'Table'[idclient] = currentClient
                    && 'Table'[status] = 3
                    && 'Table'[id] > currentID
            ),
            'Table'[id], ASC
        ),
        "@val", 'Table'[id]
    )

Thank you very much!

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors