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

Subtracting current hour's value from previous hour's value

Is there a DATEADD equivalent for hours?

 

The smallest interval for DATEADD is DAY, but I need it to be HOUR.

 

I have a running total number that grows once per hour, I need to make a measure that calculates the hourly consumption.

 

For example for monthly calculations I use

Monthly = SUM('Readings'[VALUE]) - CALCULATE(SUM('Readings'[VALUE]), DATEADD('Date'[Date], -1, MONTH))

 

I need a similar solution to calculate hourly consumption for each of the 24 hours.

 

Sample table 'Readings':

Consumption Point    DateTimeDay ValueNight Value
CP101/01/20      00:00:00    140null
CP101/01/2000:01:00145null
CP101/01/2000:02:00155null
CP101/01/2000:03:00165null
CP101/01/2000:00:00null100
CP101/01/2000:01:00null110
CP101/01/2000:02:00null115
CP101/01/2000:03:00null130

 

So I would need a measure that knows for example on 01/01/20 at hour 1 (01:00) the day consumption was 5 (145-140) etc. And for 00:00:00 the measure would have to subtract from 00:00 the 23:00 of the previous date and so forth.

 

When googling this problem I saw a solution with indexing the rows but, since there are more than one (total 4) consumption running totals for every hour then indexing the rows wouldn't work.

 

I would like to use these measures (one for each type of consumption) in a matrix table with a slicer next to it where the user can choose the date(s). The matrix table would look something like this:

 

Consumption Point/Hour    Day Consumption    Night Consumption  
CP1  
   00:01:00510
   00:02:00105
   00:03:001015

 

 

Any help would be appreciated.

 

Thanks!

2 REPLIES 2
Anonymous
Not applicable

Hey @Anonymous ,

You could try: [Consumption Point/ Hour] +/- TIME( Hrs, Mins, Secs )
eg. [00:14:00] - TIME(2,30,30) = 11:29:30

Hope that helps!

Anonymous
Not applicable

Could you explain this a bit more, I don't really see at the moment how this would work. The Consumption Point/Hour are two different columns in the database I would just use them as rows in the matrix column. And I need to do the calculation of (for example for Day Value) current hour day value minus last hour's day value (since the day value numbers in the database are running totals).

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.

Top Solution Authors