Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Running total sum with a current hour flag column

Hello I have a table called FLA with applications per state with time and date columns. There is also a current_hour_flag column that shows 1 if the time is the current hour. For instance, the ...
  • TheoC's avatar
    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