cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

Running total last 5 seconds data

Hi All,

my table is very simple 

TimeTime_5secBackValueRunningTotal
02:16:4102:16:366.595522 
02:16:4202:16:378.453462 
02:16:4302:16:386.175027 
02:16:4402:16:397.015015 
02:16:45 02:16:403.0925131.33154
02:16:4602:16:413.38133628.11735
02:16:4702:16:423.42302623.08691
......... 

 

I have to calculate the cumulative value of the last 5 seconds so basically

from sec 41 to 44 - 0

sec 45  - the sum of the previous 5 seconds - 31.33

sec 46 - the sum of the previous 5 seconds - 28.11

 

It is very easy in excel this sliding sum but I do not know how to replicate in in dax.

 

Any help appreciated

Roberto

 

 

1 ACCEPTED SOLUTION

Just use a var, this should be the equivalent measure:

 

 

Running Total =
  VAR __Time = MAX('Table'[Time]) //max of time column in current context (measure)
  VAR __Time5s = MAX('Table'[Time_5secBack])
RETURN
  SUMX(FILTER(ALL('Table'),[Time] >= __Time5s && [Time] <= __Time),[Value])

 

 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Super User IV
Super User IV

You should be able to create a column like:

 

Running Total =
  SUMX(FILTER('Table',[Time] >= [Time_5secBack] && [Time] <= EARLIER([Time])),[Value])

---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks but I would like to work with a measure and EARLIER is not suggested

Just use a var, this should be the equivalent measure:

 

 

Running Total =
  VAR __Time = MAX('Table'[Time]) //max of time column in current context (measure)
  VAR __Time5s = MAX('Table'[Time_5secBack])
RETURN
  SUMX(FILTER(ALL('Table'),[Time] >= __Time5s && [Time] <= __Time),[Value])

 

 


---------------------------------------

@ me in replies or I'll lose your thread!!!

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite with Arun Ulag

Featured Session: Drive Data Culture with Power BI- Vision, Strategy & Roadmap. Register here https://myignite.microsoft.com #MSIgnite #PowerPlatform #Power BI ​

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors
Users online (103)