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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
anonymous3
Frequent Visitor

Measure that dynamically calculates date difference between consecutive rows in a group

Hello, PowerBI community. 
I desperately need your help as this task is taking much more time than it would be worth spending on it.

I need a measure that calculates date difference between EndDate and previous StartDate in days by Group column and dynamically recalculates when particular filters are applied:

anonymous3_0-1662998651396.png


So far I tried something like this:

_DaysSinceEndElapsed = 
IF(
    SELECTEDVALUE(table[is_first_record_in_group])=True,
    BLANK(),
    DATEDIFF(
        CALCULATE(
            MAX([ExitDate]), 
            FILTER(
                ALL(table),
                table[Group] = MAX(table[Group]) &&
                table[id] < MAX(table[id])
            )
        ),
        SELECTEDVALUE(table[EndDate]),
        DAY
    )
)

but it doesn't recalculate when I apply the filters.

Please, help

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @anonymous3 ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

_DaysSinceEndElapsed =
VAR _enddate =
    CALCULATE (
        MAX ( 'table'[enddate] ),
        FILTER (
            ALLSELECTED ( 'table' ),
            'table'[Group] = SELECTEDVALUE ( 'table'[Group] )
                && 'table'[id] < SELECTEDVALUE ( 'table'[id] )
        )
    )
VAR _startdate =
    MAX ( 'table'[startdate] )
RETURN
    DATEDIFF ( _enddate, _startdate, DAY )

Then put the id column into the slicer.

vpollymsft_0-1663058954238.png

 

 

vpollymsft_1-1663058973102.png

If I have misunderstood your meaning, please provide more details.

 

Best Regards

Community Support Team _ Polly

 

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

4 REPLIES 4
anonymous3
Frequent Visitor

Hi @Anonymous 

1. Each _DaySinceEndElapsed is calculated as date difference in days between StartDate and previous EndDate. For example, in yellow group: 

anonymous3_2-1663057529739.png

 


2. Then filter is applied that just filter out every second row. So I need _DaysSinceEndElapsed recalculate like this

anonymous3_3-1663057610577.png

 


Thanks

 

Anonymous
Not applicable

Hi @anonymous3 ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

_DaysSinceEndElapsed =
VAR _enddate =
    CALCULATE (
        MAX ( 'table'[enddate] ),
        FILTER (
            ALLSELECTED ( 'table' ),
            'table'[Group] = SELECTEDVALUE ( 'table'[Group] )
                && 'table'[id] < SELECTEDVALUE ( 'table'[id] )
        )
    )
VAR _startdate =
    MAX ( 'table'[startdate] )
RETURN
    DATEDIFF ( _enddate, _startdate, DAY )

Then put the id column into the slicer.

vpollymsft_0-1663058954238.png

 

 

vpollymsft_1-1663058973102.png

If I have misunderstood your meaning, please provide more details.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you! 

Anonymous
Not applicable

Hi @anonymous3 ,

I was a little confused. In the first table, in a, the _dayssinceendelapsed value is 60 and 14? How to calculate to get the value ? And in the second table, which date was filtered so that  the result is 104? Could you pease provide more details?

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

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!

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.