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
eduardomartins
Frequent Visitor

Sumarize per Month sliced downtime

Hello there!

 

I'm trying hard to solve a problem and I'm getting nowhere here, so I need some help!

 

Here's the problem. I have a downtime table like this below:

 

table.png

 

 

 

 

 

 

 

 

 

 

 

 

 

The fisrt column (Data Inicio) is the beginning of the asset downtime, the second column (Data Fim) is the end of the asset downtime and the third column is the difference in minutes of the two first columns.

 

What I want to do it's quite simple (it should be): I want to sumarize by month the downtime, but I need to slice the downtime in each month between the beginning date and the the end date for all rows!!

 

Take for example the first row. We have 6 months between the beginning and the end of the downtime. What I want is:

 

 

table2.png

But for all the rows of the table, of course. The first month and the last one it's easy to get, because I have the reference dates, but the middle ones I couldn't think in a way to do that (and I've already tried lots of ways).

 

Can anyone help me, please? 🙂

 

Thanks!

1 ACCEPTED SOLUTION
fhill
Resident Rockstar
Resident Rockstar

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.)

 

Capture.PNG

Here is your data:

 

Capture2.PNG

 

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.

 

Capture3.PNG

 

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]

 

Capture4.PNG

 

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

 

Capture5.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




View solution in original post

6 REPLIES 6
fhill
Resident Rockstar
Resident Rockstar

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.)

 

Capture.PNG

Here is your data:

 

Capture2.PNG

 

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.

 

Capture3.PNG

 

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]

 

Capture4.PNG

 

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

 

Capture5.PNG




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




eduardomartins
Frequent Visitor

Anyone? 😞

Does this have to be in Minutes?  If you want to look at Downtime Days, I might have some ideas?

 

FOrrest




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




Hi there @fhill!

 

It could be in days, no problem. The logic would be the same, I think. 🙂

hahahahaha... MUCH Easier in Days!   But oh well, I already figured out a Minutes option...




Did I answer your question, or help you along the way?
Please give Kudos or Mark as a Solution!


https://www.linkedin.com/in/forrest-hill-04480730/

Proud to give back to the community!
Thank You!




@fhill, Thank you very much, my friend! It worked as I need it!!! 😄

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.