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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount 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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors