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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.