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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DataGirl90
Regular Visitor

Find Previous 5 Minutes Value

Hi, 

 

I'm looking to find the Sum of Value for the Previous 5 Minutes. I'm connected via Direct Query and am not able to use CALCULATE in a column. My Date Time field is in 5 minutes increment. The sample below is what I'm trying to achieve. There will be a date slicer on the page so users will be able to select the dates they would like the data for. 

DateTimeValueValue Prev 5 Minutes% Change
2/2/2023 9:15:00 AM5025100%
2/2/2023 9:20:00 AM1005050%
2/2/2023 9:25:00 AM15010033%
2/2/2023 9:30:00 AM20015025%
2/2/2023 9:35:00 AM25020020%
2/2/2023 9:40:00 AM30025016%



I've tried

CALCULATE(
SUM(Value)),
ALL(Date Time Field),
Date Time Field = MAX(Date Time Field) - TIME (0,5,0)
*This DAX worked on some rows but not all. On different days, missing values were occurring at the same time interval

CALCULATE(
SUM(Value)),
ALL(Table),
Date Time Field <= EARLIER(Date Time Field)
*This DAX doesn't work because I cannot create a column using CALCULATE with Direct Query


I've also created a column with the -5 minutes and called it Prev 5 Mins and tried this DAX below
SUM(Value)),
ALL(Table),
Date Time Field = Prev 5 Mins
*This one was returning blanks.

Can someone help me, please?


I'd like to add that I have been able to successfully use the below dax
Measure 1 = 
VAR CurrentDate = SELECTEDVALUE(Table [Date])
VAR PreviousDate = 
CALCULATE(
MAX(Table[Date]),
TAble[Date] < CurrentDate)
RETURN

CALCULATE([Measure Sum]), Table[Date] = PreviousDate

 

This DAX does work, however, given the size of my dataset, I do sometimes get the 1 mil row error problem and it does take some time for the results to display. I'm hoping someone would be able to advise me on a better method.

5 REPLIES 5
lbendlin
Super User
Super User

use two relative time filters on your visual. Something like this:

 

- is in last ten minutes

- is not in last five minutes

Hi, 

 

Applying a visual level filter would filter out the other fields in my matrix though. Also, I should have provided more information. There is a date slicer that users can use to select the dates they would like the data for. 

Create a measure that implements your logic and use that measure as a visual filter.

Hi, 

 

That's what I was asking for help with. I've updated the question with some more DAX and I was wondering if there is a better way to write the DAX. Also, I'm not sure what you mean by creating a measure and using that measure as a visual filter. I don't think that using a measure to apply a visual filter would satisfy the requirements of the report. As I've explained above, if I apply a filter on the visual, the dates would have to match the dates the users will select in the date slicer seeing as it is expected report behavior that all the visuals on the report page will interact with each other. And what measure were you thinking of specifically that I should use as a filter? My main problem in the initial post was calculating the data for the previous 5 minutes from the selected date time and then calculating the % change from it.

There is a date slicer that users can use to select the dates they would like the data for

is that fed from your fact table or from a connected dimension table (which would be weird because of the 5 minute granularity)?

 

I tested with measures and it works fine even considering the selection slicer being fed from the fact table.

 

lbendlin_0-1678374272007.pnglbendlin_1-1678374292627.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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