Forum Discussion
Grouped cumulative figures based on time
Hi,
Firstly, I am new to PBI and I don't know if this is possible. Any help would be most appreciated.
I am trying to get groups of cumulative running totals based on time. At the moment I have time and rainfall, I need to get groups for 2hr, 4hr, 6hr, 12hr, 24hr and 48hr.
I have included a full 24 hour data set, as I am testing on this, however you would be at say 1pm and then refresh the data to show hour rainfall till that point. You will then want to see over the last 2 hours how much rain has fallen, with the other groups coming in as data becomes available. This can run for a number of days, hence the bigger groups.
I don't think that my variations on the following are the right way to achieve what I am after:
Cumulative = CALCULATE(sum(Table1[Rainfall(mm/hour)]), (filter(all(Table1[Time]),table1[Time] <=MAX(Table1[Time]))))
Data example and desired out come:
| Time | Rainfall(mm/hour) | 2hr | 4hr | 6hr | 12hr | 24hr |
| 01:00 | 0.6 | |||||
| 02:00 | 1.4 | |||||
| 03:00 | 1.4 | 2 | ||||
| 04:00 | 0.6 | 2.8 | ||||
| 05:00 | 1 | 2 | 4 | |||
| 06:00 | 1 | 1.6 | 4.4 | |||
| 07:00 | 1.2 | 2 | 4 | 6 | ||
| 08:00 | 1.2 | 2.2 | 3.8 | 6.6 | ||
| 09:00 | 1.8 | 2.4 | 4.4 | 6.4 | ||
| 10:00 | 1.6 | 3 | 5.2 | 6.8 | ||
| 11:00 | 0.8 | 3.4 | 5.8 | 7.8 | ||
| 12:00 | 0.6 | 2.4 | 5.4 | 7.6 | ||
| 13:00 | 1.4 | 1.4 | 4.8 | 7.2 | 13.2 | |
| 14:00 | 1.4 | 2 | 4.4 | 7.4 | 14 | |
| 15:00 | 1.4 | 2.8 | 4.2 | 7.6 | 14 | |
| 16:00 | 0.4 | 2.8 | 4.8 | 7.2 | 14 | |
| 17:00 | 0.4 | 1.8 | 4.6 | 6 | 13.8 | |
| 18:00 | 0.2 | 0.8 | 3.6 | 5.6 | 13.2 | |
| 19:00 | 0.4 | 0.6 | 2.4 | 5.2 | 12.4 | |
| 20:00 | 0.4 | 0.6 | 1.4 | 4.2 | 11.6 | |
| 21:00 | 0.2 | 0.8 | 1.4 | 3.2 | 10.8 | |
| 22:00 | 1 | 0.6 | 1.2 | 2 | 9.2 | |
| 23:00 | 0.6 | 1.2 | 2 | 2.6 | 8.6 | |
| 24:00:00 | 0.8 | 1.6 | 2.2 | 2.8 | 8.4 | 21 |
Thanks again in advance for your time.
Hi Anonymous ,
For this, I'd create a helper table - one that doesn't have any relationship with your facts or dimension tables. This can be done through import or enter data method.
I would then create this measure
Rainfall total within hour window = VAR __window = SELECTEDVALUE ( 'Group'[Hours] ) VAR __window2 = SELECTEDVALUE ( Rainfall[Time] ) - __window - 1 RETURN SWITCH ( TRUE, __window = 0, SUM ( Rainfall[Rainfall(mm/hour)] ), __window2 < 0, BLANK (), CALCULATE ( SUM ( Rainfall[Rainfall(mm/hour)] ), FILTER ( ALL ( Rainfall[Time] ), Rainfall[Time] >= ( MAX ( Rainfall[Time] ) - __window ) && Rainfall[Time] < MAX ( Rainfall[Time] ) ) ) )Sample result
Sample pbix for your reference -https://drive.google.com/file/d/1lyxLLfQZ_iJzxuRRVx_RNx1SOYrY4Ntk/view?usp=sharing
4 Replies
- danextian
Super User
Hi Anonymous ,
For this, I'd create a helper table - one that doesn't have any relationship with your facts or dimension tables. This can be done through import or enter data method.
I would then create this measure
Rainfall total within hour window = VAR __window = SELECTEDVALUE ( 'Group'[Hours] ) VAR __window2 = SELECTEDVALUE ( Rainfall[Time] ) - __window - 1 RETURN SWITCH ( TRUE, __window = 0, SUM ( Rainfall[Rainfall(mm/hour)] ), __window2 < 0, BLANK (), CALCULATE ( SUM ( Rainfall[Rainfall(mm/hour)] ), FILTER ( ALL ( Rainfall[Time] ), Rainfall[Time] >= ( MAX ( Rainfall[Time] ) - __window ) && Rainfall[Time] < MAX ( Rainfall[Time] ) ) ) )Sample result
Sample pbix for your reference -https://drive.google.com/file/d/1lyxLLfQZ_iJzxuRRVx_RNx1SOYrY4Ntk/view?usp=sharing
- AnonymousNot applicable
Hi Danextian,
Thank you very much for this, it is what I am looking for. The only thing that is causing issues is the time, in your output time is coming through as a whole number and we are dealing with time in time format. Is there away to amend the dax? I tried hour(__window) and event rinafall[time] -__window/24, but they don't seem to work.
Thanks
- danextian
Super User
Is your time column in time format or is it a datetime? Is your time by the hour or also in minutes and seconds? The reason I used whole number is for simplicity. Also there is no 24:00 - you meant 00:00?