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
voglejm
New Member

Grouping Calculation

Hello Everyone!

I'm new to PowerBi and I'm looking for some help. I've been asked to create a calculated field that shows the amount of time that each request was open. The customer desires to see a sum of time that a request was open; however, they are wanting any hold state removed from the sum. So for the example provided below the customer would expect to see that RFS21121 was open for roughly 124 days. 

 

I'm honestly not even sure where to begin; however, I'm hoping someone can help.PowerBI.png

1 ACCEPTED SOLUTION
Nathaniel_C
Super User
Super User

Hi @voglejm ,

 

From DATEDIFF - google- I would use this function twice, and then subtract 1 from the other.

Maybe add these in a few columns so that you can confirm the correctness of each part, and then circle back and make one column out of the others. I always find it easier to debug.  So the first column might be CALCULATE(MAX(Table[Created], FILTER(ALL(Table), Table[Previous Status] = null, Table[Title])) (or maybe use table[Current Status] = something). It just needs to be consistent. That would be your first date, get the second date, and then use the DateDiff. Then do it all over for the second duration.

One other thing...in your picture the type is shown as ABC123 which is Any...that can create problems.  Always change that.

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

Syntax

DAXCopy
DATEDIFF(<start_date>, <end_date>, <interval>)  

Parameters

Term Definition
start_dateA scalar datetime value.
end_dateA scalar datetime value Return value.
intervalThe interval to use when comparing dates. The value can be one of the following:

- SECOND
- MINUTE
- HOUR
- DAY
- WEEK
- MONTH
- QUARTER
- YEAR

Return value

The count of interval boundaries crossed between two dates.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
Nathaniel_C
Super User
Super User

Hi @voglejm ,

 

From DATEDIFF - google- I would use this function twice, and then subtract 1 from the other.

Maybe add these in a few columns so that you can confirm the correctness of each part, and then circle back and make one column out of the others. I always find it easier to debug.  So the first column might be CALCULATE(MAX(Table[Created], FILTER(ALL(Table), Table[Previous Status] = null, Table[Title])) (or maybe use table[Current Status] = something). It just needs to be consistent. That would be your first date, get the second date, and then use the DateDiff. Then do it all over for the second duration.

One other thing...in your picture the type is shown as ABC123 which is Any...that can create problems.  Always change that.

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

Syntax

DAXCopy
DATEDIFF(<start_date>, <end_date>, <interval>)  

Parameters

Term Definition
start_dateA scalar datetime value.
end_dateA scalar datetime value Return value.
intervalThe interval to use when comparing dates. The value can be one of the following:

- SECOND
- MINUTE
- HOUR
- DAY
- WEEK
- MONTH
- QUARTER
- YEAR

Return value

The count of interval boundaries crossed between two dates.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I would also recommend @MattAllington 's book, Supercharge Power BI.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @voglejm ,

So the logic for each TITLE is get the date where the previous status is null, get the date where the Current status is complete. Count the diff, then get the date where the current status is 0.2 hold, get the date where the previous status is 0.2 hold, find the diff. Subtract the second diff from the first diff?  Will these values null complete 0.2 hold, always be the same?

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@Nathaniel_C  - The values may not always be the same, specifically for the Hold status'.  There are many different flavors of hold; however, they are all denoted with .2. For example, there could be a Hold status that is 1.2 or 7.2. Let me know if that helps clear it up. I appreciate any help that you can provide!!

 

Justin 

So does my logic seem to be clear, if we changed the one to contains "hold"?
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




@Nathaniel_C  The logic does make sense; however, I'm unclear on where I would define this logic. Sorry for the ignorance, I'm just not that familiar with PowerBI. If you have any tutorials or other threads you might recommend I'm happy to learn, I just didn't find anything in my initial search. 

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
Top Kudoed Authors