Forum Discussion
Sumarize per Month sliced downtime
- 9 years ago
This one was a bit crazy, so try to stick with me... ** Make sure all Date / Time columns are formatted as such! **
First, I needed to create a boarder table I called 'Months'. Since we are looking at Minutes instead of days, I had to take this down to the Time level where every month starts at 00:00:00 and every month ends at 23:59:59. You can do this easily in excel or by hand (it won't take that long.)
Here is your data:
I needed a good way to apply If / Then logic to each of your dates to see how they merge into the different months. I did this by creating a new Custom Table (not in Query Editor) under the Modeling Tab of Power BI. This CrossJoin command will mesh the two tables together for every row.
Now I can start throwing math against the problem.. here are my 4 custom columns to account for periods starting during a month, a full month, or periods ending during a month. Then a Total for easy visuals:
PartialMonthStart = IF('Table'[StartMonth] <= 'Table'[Start] && 'Table'[EndMonth] >= 'Table'[Start],DATEDIFF('Table'[Start],'Table'[EndMonth],MINUTE) + 1 )
FullMonth = IF('Table'[StartMonth] >= 'Table'[Start] && 'Table'[EndMonth] <= 'Table'[End],DATEDIFF('Table'[StartMonth],'Table'[EndMonth],MINUTE) + 1)
PartialMonthEnd = IF('Table'[StartMonth] <= 'Table'[End] && 'Table'[EndMonth] >= 'Table'[End],DATEDIFF('Table'[StartMonth],'Table'[End],MINUTE) + 1 )
*** The +1 at the end is VERY important, b/c eadh day ends at 23:59:59, I have to manaully add in the missing full minute. ***
TotalMinutesDown = 'Table'[PartialMonthStart] + 'Table'[FullMonth] + 'Table'[PartialMonthEnd]
Now that you have mutple lines per Month, you can easily create a Visual SUM'ing the Total Minutes column. See below where I have the raw data (with a calculated Durration Minutes, and then my chart with a matching SUM when looking at the values by month.
Thank You,
FOrrest
Does this have to be in Minutes? If you want to look at Downtime Days, I might have some ideas?
FOrrest
- fhill9 years ago
Resident Rockstar
hahahahaha... MUCH Easier in Days! But oh well, I already figured out a Minutes option...
- eduardomartins9 years agoFrequent Visitor
fhill, Thank you very much, my friend! It worked as I need it!!! :-D