Forum Discussion
Running Cumulative based on hours
I need your help on a DAX formula to calculate the third column 'CumulativeForTheDay' that's is required to be a running total. The required calculation will be for 24 hours starting at '01:00' AM Till midnight '00:00'.
9 Replies
- themistoklisCommunity Champion
Anonymous
Creata a new table and add as dimension the timestamp sorted in Ascending order.
Then create a measure using the following formula and add it to the table.
If you want to see the running total for a specific date, add a dare slicer and select the date you want
Cumulative = CALCULATE ( SUM ( Table[FlowAtGivenInterval] ), FILTER( ALL (Table ), Table[TimeStamp] <= MAX( Table[TimeStamp] )) )- AnonymousNot applicable
Hello themistoklis,
Thanks for taking the time to reply. The problem with your solution is that is doesn't break on new days. It keeps accumulating on consecutive days.
- AnonymousNot applicable
Hi Anonymous,
You can try to use following measure formula, I write formula to use date part as condition to limit cumulative date range:
Measure = VAR currDate = MAX ( Table[TimeStamp] ) RETURN CALCULATE ( SUM ( Table[FlowAtGivenInterval] ), FILTER ( ALLSELECTED ( Table ), OR ( DATEVALUE ( Table[TimeStamp] ) = DATEVALUE ( currDate ), Table[TimeStamp] = DATEVALUE ( currDate ) + 1 ) && AND ( Table[TimeStamp] > DATEVALUE ( currDate ), Table[TimeStamp] < currDate ) ) )Regards,
Xiaoxin Sheng
- AnonymousNot applicable
Hello Xiaoxin,
Thanks for your time. Your code is very close to what I need, it just need to provide a value at '01:00' AM as highlighted in the screenshot which will be the same value from the 'FlowAtGivenInterval' column - 78.66 - in this specific date. You can also notice that no value is available at midnight which I want its value to be accounted and included for the cumulative for this day.
Thanks again for your help.
Emad
RunningTotal =VAR currDate =MAX ( Daily_Methane_1[TimeStamp] )RETURNCALCULATE (SUM ( Daily_Methane_1[FlowAtGivenInterval] ),FILTER (ALLSELECTED ( Daily_Methane_1 ),OR (DATEVALUE ( Daily_Methane_1[TimeStamp] ) = DATEVALUE ( currDate ),Daily_Methane_1[TimeStamp]= DATEVALUE ( currDate ) + 1)&& AND ( Daily_Methane_1[TimeStamp] > DATEVALUE ( currDate ), Daily_Methane_1[TimeStamp] < currDate )))- AnonymousNot applicable
Hi Anonymous,
Can you please provide some sample data so that we can test and modify dax formula in power bi side?
Regards,
Xiaoxin Sheng