Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

DAX to display the last number of days since the last ticket sold

Hi,

I have a requirement to display the last number of days since the last ticket sold e.g in the below screenshot I want to display 977 for a client.

SaloniGupta_0-1625193392253.png

Here is the DAX to calculate the "Days since the last ticket sold" from the Transaction FACT table.

Days Since Last Ticket Sold =
DATEDIFF(MAX('Transaction'[Transaction Date Key]),TODAY(),DAY)

Please let me know if you need more information.
Thanks in Advance!
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try a new measure like

Days Since Last Ticket Sold =
var _max = MAXX(allselected('Transaction'),'Transaction' [Transaction Date Key])
return
if(MAX('Transaction'[Transaction Date Key]) =_max, DATEDIFF(MAX('Transaction'[Transaction Date Key]),TODAY(),DAY), blank())

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Try a new measure like

Days Since Last Ticket Sold =
var _max = MAXX(allselected('Transaction'),'Transaction' [Transaction Date Key])
return
if(MAX('Transaction'[Transaction Date Key]) =_max, DATEDIFF(MAX('Transaction'[Transaction Date Key]),TODAY(),DAY), blank())

Anonymous
Not applicable

Hi @amitchandak,
I found a problem with the above logic you gave.
This works for 1 Client, but when I have all the clients, it gives results for only those Clients who have the latest/recent Transaction Date.
e.g in the below sample for client "Applause A" Days Since Last Ticket Sold logic should show 520 for Feb-2020

SaloniGupta_0-1625630523719.png

but the logic works for only those clients who have recent transactions (latest date), here it shows 6 days when the latest transaction date was in June 2021 for Client Moon B

SaloniGupta_1-1625630732914.png

Is there a way to correct this and show Days Since the Last Ticket Sold for each client and not only for clients who have the recent/latest transaction date?
Please let me know if you need more information from my end.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.