Forum Discussion
Calculating a Total Based on Start/End Dates
I have a data set that includes Start/End Dates, Site, Object, and ObjectAttributeX (a number equal to or less than 1).
I need to calculate Total ObjectAttributeX for a Site.
If an Object's AttributeX changes, an end date is added and there is a new line with a new start date and the new AttributeX.
If the Object stops being used, an end date is put in, ex:
| Line# | Start Date | End Date | Site | Object | ObjectAttributeX |
| 1 | 7/1/2019 | 5 | A | 0.90 | |
| 2 | 7/1/2019 | 5 | B | 1.00 | |
| 3 | 7/1/2019 | 2/29/2020 | 5 | C | 0.50 |
| 4 | 3/1/2020 | 5 | C | 0.20 | |
| 5 | 7/1/2019 | 3/31/2020 | 5 | D | 1.00 |
| 6 | 4/1/2020 | 5 | D | 0.80 | |
| 7 | 7/1/2019 | 5 | E | 0.75 | |
| 8 | 7/1/2019 | 12/31/2019 | 5 | F | 0.85 |
| 9 | 7/1/2019 | 5 | G | 0.25 |
I want PowerBI to give me a summary like this (preferably with the Date as a Slicer filter):
| Site 5 | N | Total ObjectAttributeX |
| July 2019 | 7 | 5.25 |
| March 2020 | 6 | 4.10 |
| April 2020 | 6 | 3.90 |
TYIA
ETA: this has nothing to do with time.
My issue is when I sum March 2020 I need a formula that uses (for example) the first line for Object D (1.00) and when I sum April 2020 I need it to use the second line for Object D (0.80). hope this helps clarify my issue.
16 Replies
- AnonymousNot applicable
Hey Anonymous
Power BI does not support Duration formats or calculations so you will need to convert your dates to numbers of either days, minutes, etc. See the below links for more on this:
https://community.powerbi.com/t5/Desktop/Duration-format/td-p/447543
If this helps please kudo.
If this solves your problem please accept it as a solution.
- Greg_Deckler
Community Champion
Chelsie Eiden's Duration: https://community.powerbi.com/t5/Quick-Measures-Gallery/Chelsie-Eiden-s-Duration/m-p/793639#M389
The other reply is technically incorrect, Power BI does support duration formats now.
- AnonymousNot applicable
Greg_DecklerI'm wondering if I confused the issue by calling the column I'm trying to sum "time"?
I've editted my post above.
My issue is when I sum March 2020 I need a formula that uses (for example) the first line for Object D (1.00) and when I sum April 2020 I need it to use the second line for Object D (0.80). I don't think time/duration plays into it?
- Greg_Deckler
Community Champion
Now I'm confused, I done understand how you are getting from the sample source data to your desired results.
- AnonymousNot applicable
Greg_Deckler I may be incorrect and I would defer to your judgment for sure on that, but I'm going to ask for clarification for myself because unless I am mistaken the link you posted converts the days, hours, and seconds to numbers and then sticks them in a custom format to generate the appearance of duration. I know duration is supported in Power Query (M): https://docs.microsoft.com/en-us/powerquery-m/duration-functions, but it seems your article follows a similar process to the link I posted.
- Greg_Deckler
Community Champion
Anonymous - Both Power Query and Power BI's representation of Dates, Time and Duration is a trick. It's all just decimal numbers. You can provie this to yourself in Power Query if you right-click a "Duration" column and switch it to decimal number. You get a decimal number. Switch it back, it is magically a duration. Dates and Times in DAX are the same trick, it's just a decimal number behind the scenes.
So, converting somethingt that is formatted as a duration to a number, it's just a matter of whether it happens automatically or not. The problem that was fixed by Chelsie Eiden is that Power BI had no capability to display an aggregation as a duration format. So, even if you converted something to a number, added it up, etc. you had to convert it back to text to display it as a duration. Chelsie Eiden fixed that in Power BI so that you can have a number but display it as a duration, just like you can have a number and display it as a date.
I could actually argue this both ways. One, Power BI always supported duration because duration is just a decimal number. Conversely, Power BI never supported duration until Chelsie Eiden because you could never display an actual duration format, it always had to be converted to text. Either way, in my opinion, Power BI now supports Durations post Chelsie Eiden's work whereas previously it did not. I think you might be getting hung up on the fact that "duration" is not a "native data type". Well, it isn't in Power Query either because internally it is just a decimal number. Is duration in Power BI Desktop as nice and friendly as in Power Query? No, but it is definitely good enough to check the box of being supported.