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
Pjotr
Frequent Visitor

Create new table that summarizes subsequent values based on ID

Hi everyone,

 

I am currently having a dataframe in the following format:

 

Dataset_current.png

 

 

 

 

 

 

 

 

 

 

I would like to analyse the status transitions that occur and the time these transitions take.

For this I would like to obtain a dataset in the following format:

 

dataset_wanted.png

 

 

 

 

 

 

 

 

However, I am struggling to find a way to do this in DAX.

Does anyone have a suggestion on how this can be obtained?

 

Thanks in advance.

1 ACCEPTED SOLUTION

@Pjotr

 

You can use this calculated table

 

From the Modelling Tab >> NEw Table

 

Calculated Table =
VAR temp =
    ADDCOLUMNS (
        Table1,
        "Status New",
        VAR nextrow =
            TOPN (
                1,
                FILTER ( Table1, [ID] = EARLIER ( [ID] ) && [Day] > EARLIER ( [Day] ) ),
                [Day], ASC
            )
        RETURN
            MINX ( nextrow, [Status] ),
        "Days Between",
        VAR nextrow =
            TOPN (
                1,
                FILTER ( Table1, [ID] = EARLIER ( [ID] ) && [Day] > EARLIER ( [Day] ) ),
                [Day], ASC
            )
        RETURN
            MINX ( nextrow, [Day] ) - [Day]
    )
RETURN
    SELECTCOLUMNS (
        FILTER ( temp, NOT ( ISBLANK ( [Status New] ) ) ),
        "ID", [ID],
        "Status Old", [Status],
        "Status New", [Status New],
        "Days Between", [Days Between]
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

5 REPLIES 5
javi0unavailabl
Resolver II
Resolver II

Please, can you explain what do you mean with "status transitions" ? I don't know why the second table is constructed using the first.

 

Thanks.

Each ID takes on different status values over time.

For ID 1, the status values are 0 > 1 > 3 > 5.

I am interested in the transitions, so going from 0 > 1, 1 > 3, etc.

The value I would like to know for each transition is the difference in days between the two status values.

So for ID 1 and transition 0 > 1, this is 11-0 = 11 days.

For ID 1 and transition 1 > 3, this is 21-11 = 10 days.

@Pjotr

 

You can use this calculated table

 

From the Modelling Tab >> NEw Table

 

Calculated Table =
VAR temp =
    ADDCOLUMNS (
        Table1,
        "Status New",
        VAR nextrow =
            TOPN (
                1,
                FILTER ( Table1, [ID] = EARLIER ( [ID] ) && [Day] > EARLIER ( [Day] ) ),
                [Day], ASC
            )
        RETURN
            MINX ( nextrow, [Status] ),
        "Days Between",
        VAR nextrow =
            TOPN (
                1,
                FILTER ( Table1, [ID] = EARLIER ( [ID] ) && [Day] > EARLIER ( [Day] ) ),
                [Day], ASC
            )
        RETURN
            MINX ( nextrow, [Day] ) - [Day]
    )
RETURN
    SELECTCOLUMNS (
        FILTER ( temp, NOT ( ISBLANK ( [Status New] ) ) ),
        "ID", [ID],
        "Status Old", [Status],
        "Status New", [Status New],
        "Days Between", [Days Between]
    )

Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad Exactly what I needed, thanks a lot! 

@Pjotr

 

See the File attached as well

 

crte.png


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.