Forum Discussion
Running total sum with a current hour flag column
- 5 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
Hello Theo, your calculated hour flag column solved my issue and I was able to use my previous measure. However, would you know how to adjust it so I could have a time slicer that would change the current hour to my selection?
In other words, show the application count sum for the past 30 days at the hour I select.
Anonymous great to hear it worked, mate! It was probably one of the more complex ones I've got to work on here in the Community! It is always fun to learn new things, so thank you for posting!
I am not aware of a way to link the two due to the Current Hour Flag dictates the way in which the measure works to return them (i.e. it's progressive according to the current hour).
However, I believe there may be a way whereby you can create a dynamic measure based on a Slicers selected values. So, the way that you would want to establish the measure with with logic that can apply the following:
Dynamic Measure = IF a user has selected an option from the Hour Slicer then present [Current Hour Measure] else present [Hour Measure]...
Actually, I just found this post here which is very closely aligned with the above lol: https://community.powerbi.com/t5/Desktop/Dynamic-Measure-Values-Based-on-Slicer-Selection-with-Options/m-p/230151
Anyway, if you're happy with the solution relative to this post, make sure to mark it as solved and many thanks for posting your topic. It's been fun!