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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Moving Range with time

I'm trying to get the time from one row to the next to determine how much time has elapsed from each entry.

 

I'm currently using this DAX statement: 

Moving Range = 
VAR a =
    CALCULATE (
        FIRSTNONBLANK ( Query1[Time], 1 ),
       FILTER(
        'Query1',
        'Query1'[Test]= EARLIER('Query1'[Test] - 1  ))
    )
RETURN
    IF ( a = BLANK (), BLANK(), DATEDIFF( a , Query1[Time],MINUTE))

 

 

But it gives me an error when I use it. I've posted some sample data to assist with this.

 

Same Day: is an index that indicates to me that the entry is the same day.

Test:  is the index of the events that are on the same day.

 

 

image.png

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous, 

 

You can add an index column in Query Editor. Then create a calculated column like below: 

 

Moving Range = var pre= CALCULATE(SUM('Table'[Time]),FILTER('Table','Table'[Same day Count]=EARLIER('Table'[Same day Count])&&'Table'[Index]=EARLIER('Table'[Index])-1))
return IF(pre=BLANK(),BLANK(),DATEDIFF(pre,'Table'[Time],MINUTE))

 

q3.PNG

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
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-qiuyu-msft
Community Support
Community Support

Hi @Anonymous, 

 

You can add an index column in Query Editor. Then create a calculated column like below: 

 

Moving Range = var pre= CALCULATE(SUM('Table'[Time]),FILTER('Table','Table'[Same day Count]=EARLIER('Table'[Same day Count])&&'Table'[Index]=EARLIER('Table'[Index])-1))
return IF(pre=BLANK(),BLANK(),DATEDIFF(pre,'Table'[Time],MINUTE))

 

q3.PNG

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
HotChilli
Super User
Super User

First question : what's the error?

Doesn't the offending text get highlighted in the formula?

 

It looks like there's a bracket out of place in the EARLIER clause

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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