Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Time intelligence for hours

Here is my problem:

 

I have hourly data that can be graphed per hour and perform operations such as forecasting.

 

31.PNG

 

However, When trying to do a cumulative sum per month of the energy used (time intelligence), I can only get it in the resolution of days, not hours. Clarifying, the output is more blocky since the cumulative output is the sum per day; I would like output to represent sum per hour which would be more jagged like the example above.

 

30.PNG

 

My data looks like this. (for 10 days)

 

 

26.PNG35.PNG27.PNG

 

This is my cumulative sum calculation and it successfully accumulates the energy per month. Note StartTime is what is used for the date input.

29.PNG// [Sum of Energy = Sum(data)].

  

The problem happens when creating a visual. 

 

I am able to get a working cumulative sum visual when using [Dated] as my axis (see second photo). The resolution is days which is expected.

 

HOWEVER, when using [StartTime] as my axis, my cumulative sum calculation breaks and my visual is my data shown per hour, not cumulative summed per month:

 

36.PNG

 

Any suggestions are much appreciated!

 

 

1 ACCEPTED SOLUTION

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.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

Can you post your data in a format that can be copied and pasted easily instead of images? Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

That being said, I am working on some Quick Measures for "Time Intelligence the Hard Way". Here is an example of a calculation for Total Year To Date. You should be able to use the same basic technique.

 

TotalYTDHW = 
VAR __MaxYear = MAX('Years'[Year])
VAR __MaxMonth = MAX('Months'[MonthSort])
VAR __TmpTable = CALCULATETABLE('TheHardWay',ALL('Years'[Year]),All('Months'[Month]))
RETURN SUMX(FILTER(__TmpTable,[Year]=__MaxYear && [MonthSort] <= __MaxMonth),[Value])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I just posted the Quick Measures here:

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Holy, thanks for diving into this topic this thoroughly. 

 

Can you help me implement a MTD with the hour resolution though? I'm new to DAX and find the syntax a bit difficult.

 

From your code,

 

TITHW_TotalYTDHW =
VAR __MaxYear = MAX('Years'[Year]) //change to max month?
VAR __MaxMonth = MAX('Months'[MonthSort]) //change to max day?
VAR __TmpTable = CALCULATETABLE('TheHardWay',ALL('Years'[Year]),All('Months'[Month])) //why reference this table?
RETURN SUMX(FILTER(__TmpTable,[Year]=__MaxYear && [MonthSort] <= __MaxMonth),[Value])

 

 

Currently I have my full date and time in PiEnergy[StartTime], and my data in PiEnergy[EnergyConsumed].

 

I understand I should make columns of the month and day and hour numerically, ie (jan =1)

 

 

For clarity, can you reply with a TITHW_TotalMTDHW formula and how to create 'TheHardWay' or reference my own table to implement this DAX?

 

Thanks for your patience.

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.

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.