Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Time intelligence for hours

Here is my problem:   I have hourly data that can be graphed per hour and perform operations such as forecasting.     However, When trying to do a cumulative sum per month of the energy us...
  • Greg_Deckler's avatar
    Greg_Deckler
    8 years ago

    Hmm, perhaps something like the following, also see attachment.

     

    I started with a single table PiEnergy with [StartTime] and [EnergyConsumed] columns.

     

    I created the following calculated columns (you could use ADDCOLUMNS to do this within the measure but that doesn't seem necessary and this is more efficient.

     

    Month = MONTH([StartTime])
    
    Day = DAY([StartTime])
    
    Hour = HOUR([StartTime])

    The measure is very similar to the technique mentioned earlier with the wrinkle of the time component, requiring two separate calculations:

     

    TITHW_TotalMTDHW = 
    VAR __curMonth = MAX(PiEnergy[Month])
    VAR __curDay = MAX(PiEnergy[Day])
    VAR __curHour = MAX(PiEnergy[Hour])
    VAR __tmpTable = CALCULATETABLE(PiEnergy,ALL(PiEnergy[StartTime]))
    VAR __previousDaysConsumption = SUMX(FILTER(__tmpTable,[Month] = __curMonth && [Day] < __curDay),[EnergyConsumed])
    VAR __currentDayConsumption = SUMX(FILTER(__tmpTable,[Month] = __curMonth && [Day] = __curDay && [Hour] <= __curHour),[EnergyConsumed])  
    RETURN __previousDaysConsumption + __currentDayConsumption

    Let me know if this works or needs tweaking.