Forum Discussion
Running total sum with a current hour flag column
- 4 years ago
Hi @aaronzheng
I tested my theory this morning and, if I understand what you are wanting which is to show all of the Current Hour Flags for the past n number of days, all you need to do is create a Calculated Column that says to return the current date and time if it equals the Current Hour Flag.
col_Current_Hour_Flag = IF ( Table1[Current_Hour_Flag] = 1 , Table1[ApplicationHourEST] , BLANK() )The output gives you the Current Hour and, when added to the visual with the measure I created in the earlier post being mea_Cumulative_Day, it gives you the total cumulative at the current hour for the "Current Hour Flag". The new column uses the ApplicationHourEST and only presents a Date/Time if the Current Hour Flag is true and you use this new column as your X-Axis. Important, ensure you convert the output to Data/Type = Date/Time and then when you drag it in as the X-Axis on the visual, change it from Date Hierarchy to standard Date/Time.
I did notice one thing in my previous mea_Cumulative_Day measure in that it didn't add the ApplicationCount between 00:00 to 01:00 or the ApplicationCount in the 09:00 parameter. The reason for the 09:00 is because it includes all counts > 09:00 and < 10:00. But, to get the 503 count, I have modified my earlier measure to the below:
mea_Cumulative_Day = VAR _CurTime = MAX ( 'Table1'[ApplicationHourEST] ) RETURN IF ( TIMEVALUE ( _CurTime ) <> TIME ( 0 , 0 , 0 ) , CALCULATE ( SUM ( Table1[ApplicationCount] ), FILTER ( ALLSELECTED ( Table1 ), AND ( Table1[ApplicationHourEST] >= DATEVALUE ( _CurTime ) , 'Table1'[ApplicationHourEST] <= _CurTime ) ) ) , CALCULATE ( SUM ( Table1[ApplicationCount] ) + 0 , FILTER ( ALLSELECTED ( Table1 ) , DATEVALUE ( Table1[ApplicationHourEST] ) = DATEVALUE ( _CurTime ) - 1 ) ) )In the event that your "Current Hour Flag" is a measure, just convert the Calculated Column to a Measure. In my data, I have set up the Current Hour Flag as a column, therefore, I've used this as the reason for creating a Calculated Column in this below example.
Please accept this as a solution if it is what you are after.
Thanks,
Theo
Hi Theo, I don't understand how to implement your method. I created the current_day_flag column, but how would I use it to adjust my dax measure.
Heres a link to my sample data (didn't allow me to attach an excel file), the current hour at this time was 9:00 am.
Hi Anonymous
Okay, so finally got to this. Apologies for the delay and it required a little more effort than I thought... The "m1" measure is representative of yours and the "mea_Cumulative2" is the new measure. I've tried to keep the names of the columns as aligned as possible.
mea_Cumulative2 =
VAR _CurTime = MAX ( 'Table1'[ApplicationHourEST] )
RETURN
IF (
TIMEVALUE ( _CurTime ) <> TIME ( 0 , 0 , 0 ) ,
CALCULATE (
SUM ( Table1[ApplicationCount] ),
FILTER (
ALLSELECTED ( Table1 ),
AND ( Table1[ApplicationHourEST] >= DATEVALUE ( _CurTime ) , 'Table1'[ApplicationHourEST] < _CurTime )
)
) ,
CALCULATE (
SUM ( Table1[ApplicationCount] ) + 0 ,
FILTER (
ALLSELECTED ( Table1 ) ,
DATEVALUE ( Table1[ApplicationHourEST] ) = DATEVALUE ( _CurTime ) - 1 )
)
)
Hope this is what you wanted! 🙂
- Anonymous4 years agoNot applicable
Hey Theo, I really appreciate the effort you put into this. However, this is not exactly what I wanted. I forgot to mention that there is a current hour flag slicer that affects the visualization. When the slicer is set to 1, the line graph only plots the application count at the current hour (in this case 9:00 am ) for the last 30 days. In other words, it shows the application count at 9:00 am for the past 30 days.
In this screenshot it is filtered on CA (state) and shows the application count at the current hour (9:00 am). I am working on adjusting your mea_Cumulative2 measure to incorporate the current hour because currently it doesn't work with the current_hour_flag slicer. (It doesn't appear on the visual)
The screenshot above also shows 49 as the application count for CA on 10/9/2021 at 9:00 am, but I want it to show 510 as the sum of the application counts on 10/9/2021 until 9:00 am. 510 is the sum of the application counts (3rd column) shown below in this screenshot:
Thanks, Aaron.- TheoC4 years ago
Community Champion
Hi Anonymous, just to confirm, all you are wanting is to return the max of my measure at the Current Hour Flag? If that is correct, you should be able to add a second measure that encompasses my existing measure to return the max value when Current Hour Flag is equal to the current hour of the ApplicationHourEST.
Give it a go, I won't be in front of computer until Monday. But make sure to let me know how it goes.
- Anonymous4 years agoNot applicable
I don't believe your measure gives the correct sum, but I'll give it a go.