cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
E12345
Helper I
Helper I

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!:
Mastering Power BI 2nd Edition

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
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors