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

Need a DAX function to show percentage counts in current Qtr over counts in previous Qtr

Hi!

I am relatively new to DAX, and I really need some help and hope to get some answers/ideas from the PBI Community. 
I need a DAX function that would help me calculate (as percentage) a number of Closed Tickets in "Current Qtr" over Total Number of Open Tickets in Prior Qtr. I will provide a dummy sample data in Excel, if needed. 

Here is a snapshot of my Excel Data (I will attach a PBIX with it): 

 

E12345_0-1685666416045.png

 

In the above snapshot, the column that defines a separate quarter is shown as "Quarter End Date"
For Example, Quarter that ends in 3/1/2023 has 3 tickets with Status "Closed"
The previous Quarter, Qtr that ends on 12/31/2022, has 6 tickets with Status "Open"
So, for Qtr 3/1/2023 I need to calculate Closed over Open Percentage, which is 3 / 6 * 100 = 50 %
I need those numbers calculated for every Qtr
(distinct count of closed tickets over distinct count of open tickets in perviosu quarter) 
So, what I need is somethign like that as a line chart, with each Quarter as the X-axis and the Percentage as Y Axis:

E12345_1-1685666577668.png
Can you please provide a dax for this particular visual? Please note that I cannot create my own columns, so I have to deal with whatever columns I have. 

 

I have a PBIX sample with data, but I can't seem to find how to attachi it... Sorry. 

 



1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@E12345 

you can try to create a measure

Measure = 
VAR _open=countx(FILTER(all('Table'),'Table'[date]=EOMONTH(max('Table'[date]),-3)&&'Table'[status]="Open"),'Table'[ticket no])
return if(ISBLANK(_open),BLANK(),countx(FILTER('Table','Table'[status]="Closed"),'Table'[ticket no])/_open)

1.PNG

pls see the attachment below





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
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

I don't see how to share my PBIX here - there s no icon to download....

Somehow the other helper who offered a solution shared his PBIX - it is perfect for my needs, except I must have a DAX to calculate the distinct count of tickets (not just the count). Is there a way have a dax that would work with the distinct count of closed tickets over distinct count of open tickets? 

You may upload the file to Google Drive and share the download link here.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ryan_mayu
Super User
Super User

@E12345 

you can try to create a measure

Measure = 
VAR _open=countx(FILTER(all('Table'),'Table'[date]=EOMONTH(max('Table'[date]),-3)&&'Table'[status]="Open"),'Table'[ticket no])
return if(ISBLANK(_open),BLANK(),countx(FILTER('Table','Table'[status]="Closed"),'Table'[ticket no])/_open)

1.PNG

pls see the attachment below





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

Proud to be a Super User!




Hi, 

Wow, thank you for the prompt response! Your solution did work (so excited!!), but I realized that my actual data needs to have a "distinct count" of tickets instead of just count (you use COUNTX to get the count). Is there a way to revamp your formula to pick up distinct count of closed tickets over distinct count of open tickets (so, if some tickets have the same number, they ought to be counted as one ticket)? THANKS!!!

UPDATE: I was able to modify your function to work for distinct counts (hip hip hurray!).
For some reason I cannot figure out hot to upload the PBIX with the new finction (if anyone could direct me, that would be great!). The new Dax works perfectly with distinct counts and I tested it out with my real data as well. 
Will paste it here if anyone neeeds it (I set the format to Percent (%) to show that values as percentages)

Measure Distinct Counts =
VAR _Open =
calculate(
DISTINCTCOUNT('Table'[ticket no]),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[status]="Open"
&& 'Table'[date] = EOMONTH (MAX ( 'Table'[date]), -3)
)
)

VAR _closed =
calculate(
DISTINCTCOUNT('Table'[ticket no]),
FILTER (
ALLSELECTED ( 'Table' ),
'Table'[status]="Closed"
&& 'Table'[date] = EOMONTH (MAX ('Table'[date]), 0)
)
)

Return
if(ISBLANK(_closed),0, Divide(_closed, _open))
 
E12345_0-1685730641375.png

THANK YOU AGAIN! 






 

you are welcome





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

Proud to be a Super User!




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.