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
E12345
Resolver II
Resolver II

Deed a Dax for Average Number of Months a Ticket is Open, Within a Quarter

Hi! 
I need to calculate an average number of months a ticket is open and dispay this average on a line chart, per each quarter. 
Below is a sample dummy dataset with the columns I need to operate on. 

The "months ticket open" dax calculation should always depend on the status of the ticket. 
If status is "Open" then the "Months Ticket Open" shoupd be calculated by taking the difference in months between Open_Date and Quarter_End_Date. 
If status is "Closed" then the "Months Ticklet Open" shoupd be calculated by taking the difference in months between Open_Date and Closed_Date. 
Once the "Months Ticket Open" value is obtaned, I need to calculate an "Average Months Ticket Open" value per each Quarter and display it in a chart (each Quarter is defined by Quarter_End_Date column). 

E12345_0-1686071392002.png

Thank You!

1 ACCEPTED SOLUTION

I described the logic above, but as I set to describe it in more details, I accidentally solved it myself! I realized that what I needed really is an iterator function that would "wrap" my "datediff" logic. So, here is the key function that solved my issue: 

Months Ticket Open =
SUMX (
'Table',
IF (
'Table'[Ticket_Status] = "Closed",
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Ticket_Closed Date], MONTH ), --- Status is Closed
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Quarter_End_Date], MONTH ) --- Status is Open
)
)

In order to calculate the Average, I also ended up using AVERAGEX iterator:
AVG Months Ticket Open =
AVERAGEX (
'Table',
IF (
'Table'[Ticket_Status] = "Closed",
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Ticket_Closed Date], MONTH ),
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Quarter_End_Date], MONTH )
)
)

E12345_0-1686244401999.png

And next I just took the average 

E12345_1-1686244654966.png

 

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@E12345 Going to be a variation of this: Open Tickets - Microsoft Fabric Community

 

If you can post sample data as text can potentially be more specific.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I have seen people inserting sample PBIX files (with sample data), but I do not see any such attachment options here. Can you direct me to one? Maybe past a screenshot on where to click to add the attachment... So strange that I cannot do it and others can. 

Update: Apparently some new members do not have rights to upload files. So, it seems that I do not have the rights to upload a PBIX file.  
But I can paste a copy of the dummy data below, which you can copy into an Excel file and upload into your PBIX (?):

Quarter_End_DateTicket_NoTicket_StatusOpen DateClosed Date
3/1/20231Open1/1/2000 
3/1/20232Closed1/2/20002/4/2023
3/1/20233Closed1/3/20002/5/2023
3/1/20234Open1/4/2000 
3/1/20235Open1/5/2012 
3/1/20236Closed1/6/20002/8/2023
3/1/20237Open1/7/2000 
3/1/20238Open1/8/2000 
12/31/20229Open1/9/2000 
12/31/202210Closed1/10/20002/12/2023
12/31/202211Open1/11/2000 
12/31/202212Closed1/12/20182/14/2023
12/31/202213Closed1/13/20002/15/2023
12/31/202214Open1/14/2000 
12/31/202215Open1/15/1978 
12/31/202216Open1/16/2000 
12/31/202217Open5/17/1999 
12/31/202218Closed1/18/20002/20/2023
9/30/202219Open1/19/2000 
9/30/202220Open1/20/2000 
9/30/202221Closed1/21/20002/23/2023
9/30/202222Open1/22/2000 
9/30/202223Open1/23/2000 
9/30/202224Open3/24/2000 
9/30/202225Open1/25/2000 
9/30/202226Open1/26/2000 
6/30/202227Closed1/27/20003/1/2023
6/30/202228Open1/28/2000 
6/30/202229Open1/29/2000 
6/30/202230Closed1/30/20003/4/2023
6/30/202231Open1/31/2000 
6/30/202232Open2/1/2000 
6/30/202233Open2/2/1995 
6/30/202234Closed2/3/20003/8/2023
6/30/202235Open2/4/2021 
6/30/202236Open2/5/2000 
6/30/202237Open2/6/2016 
3/31/202238Open2/7/2000 
3/31/202239Open 2/8/2013 
3/31/202240Open 2/9/2000 
3/31/202241Closed2/10/20053/15/2023
3/31/202242Closed2/11/20123/16/2023
3/31/202243Closed2/12/20003/17/2021
3/31/202244Open2/13/2022 
3/31/202245Closed12/14/20213/19/2023
3/31/202246Open2/15/2000 

@E12345 

what's the expected output based on the sample data you provided? and what's the calculation logic?





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

Proud to be a Super User!




I described the logic above, but as I set to describe it in more details, I accidentally solved it myself! I realized that what I needed really is an iterator function that would "wrap" my "datediff" logic. So, here is the key function that solved my issue: 

Months Ticket Open =
SUMX (
'Table',
IF (
'Table'[Ticket_Status] = "Closed",
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Ticket_Closed Date], MONTH ), --- Status is Closed
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Quarter_End_Date], MONTH ) --- Status is Open
)
)

In order to calculate the Average, I also ended up using AVERAGEX iterator:
AVG Months Ticket Open =
AVERAGEX (
'Table',
IF (
'Table'[Ticket_Status] = "Closed",
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Ticket_Closed Date], MONTH ),
DATEDIFF ( 'Table'[Ticket_Open Date], 'Table'[Quarter_End_Date], MONTH )
)
)

E12345_0-1686244401999.png

And next I just took the average 

E12345_1-1686244654966.png

 

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.