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
Mann
Resolver III
Resolver III

Increments of 1 for consecutive records and process to repeat after breaks

Hi Guys,

 

I am trying to implement this logic but couldn't make it so far. This is as follows:

I have a table with Individual IDs and Date. I am trying to calculate a column which should show increments of 1 for consecutive records per Individual ID and break if concequtive records for a particular Individual ID is not present. It should repeat the above process if again consecutive records are present.

Following is the example. Column is blue is expected one:

 

Output.PNG

For e.g: For Individual ID: 111, for consecutive records from 8/8/2018 to 8/11/2018 increments of 1 is there starting from 0. For 8/13/2018 it breaks as this is not consecutive to 8/11/2018 so values is 0. It again starts from 8/21/2018 to 8/24/2018.

 

Please advice!

1 ACCEPTED SOLUTION
v-cherch-msft
Employee
Employee

Hi @Mann 

You may add an index column first.Then create below columns to it.

Column =
VAR pre_dates =
    CALCULATE (
        MAX ( Table1[Dates] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Individual ID] ),
            Table1[Index]
                = EARLIER ( Table1[Index] ) - 1
        )
    )
RETURN
    IF ( Table1[Dates] = pre_dates + 1, 0, 1 )
Column 2 = SUMX(FILTER(Table1,Table1[Index]<=EARLIER(Table1[Index])),Table1[Column])
Column 3 = RANKX(FILTER(Table1,Table1[Column 2]=EARLIER(Table1[Column 2])),Table1[Index],,ASC)

1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-cherch-msft
Employee
Employee

Hi @Mann 

You may add an index column first.Then create below columns to it.

Column =
VAR pre_dates =
    CALCULATE (
        MAX ( Table1[Dates] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Individual ID] ),
            Table1[Index]
                = EARLIER ( Table1[Index] ) - 1
        )
    )
RETURN
    IF ( Table1[Dates] = pre_dates + 1, 0, 1 )
Column 2 = SUMX(FILTER(Table1,Table1[Index]<=EARLIER(Table1[Index])),Table1[Column])
Column 3 = RANKX(FILTER(Table1,Table1[Column 2]=EARLIER(Table1[Column 2])),Table1[Index],,ASC)

1.png

Regards,

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi,

 

This works as expected. It was great help! I just need to subtract RANK by 1 as I want order to start from 0.

 

I have one more question: Can this be done using measures? (Seems like that I want to achieve at last)

I know EARLIER() doesn't work in measures as like calculated columns, but can this be done dynamically using measures?

For e.g. If some filters are selected then on the returned result this final column should comes as per same logic?

 

Thanks

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.