Forum Discussion
Datediff in DAX
I have multiple ticket ids of an order, now I want to find out if those ticket ids occur 3 or more times within 30 days. Can anyone suggest? columns are ticket_id and Dispactch_date.
7 Replies
- Greg_Deckler
Community Champion
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882
Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.It's really difficult to even suggest an answer as any possible answer is dependent on whether you want a measure, column and the visualization context, etc.
- amitchandak
Super User
ishanjain , Join Dispactch_date with date calendar
ant try a measure like this
Rolling 30 day = CALCULATE(count(ticket [ticket Id]),DATESINPERIOD('Date'[Date],MAX(ticket[Dispactch_date]),-30,Day))
Rolling 30 day = CALCULATE(count(ticket [ticket Id]),DATESINPERIOD('Date'[Date],MAX('Date'[Date),-30,Day))You can use this in Sumx or countx filter of at visual filter
link countX(filter(summarize(ticket,ticket [ticket Id],"_1", CALCULATE(count(ticket [ticket Id]),DATESINPERIOD('Date'[Date],MAX('Date'[Date),-30,Day)) ),[_1]>3),[ticket Id])
- AnonymousNot applicable
ishanjain Can you share some sample data? That will help us in resolving your problem quickly.
Thanks
- ishanjainFrequent Visitor
Edit 1: I can not share the data but will provide as much info possible.
I only have 1 table that consists of everything. There is a ticket_id (numerical) and dispatch date (ddmmyy hrs min sec) format and has data of one year. I want ticket_ids as output that have been dispatched 3 or more times within 30 days. These could be any 30 days and not necessarily month to month.
- Fowmy
Super User
ishanjain
Add the following code to your table where you have the Ticket ID and the Despatch Date. The new column will show you numbers if the same ticket appeared more than or equal to 3 times within 30 days otherwise zero will appear.You can download the file: HERE
Over 2 Tickets With 30 Days = VAR CURRENT_TICKET = [Ticket ID] VAR CURRENT_DATE = [Despatch Date] VAR MINDATE = FIRSTDATE( FILTER( VALUES(TICKETS[Despatch Date]), ABS(DATEDIFF(TICKETS[Despatch Date],CURRENT_DATE,DAY))<=30 ) ) VAR MAXDATE = LASTDATE( FILTER( VALUES(TICKETS[Despatch Date]), ABS(DATEDIFF(TICKETS[Despatch Date],CURRENT_DATE,DAY))<=30 ) ) VAR TICKTCOUNT = COUNTROWS( FILTER( TICKETS, TICKETS[Ticket ID]=CURRENT_TICKET && TICKETS[Despatch Date]>=MINDATE && TICKETS[Despatch Date]<=MAXDATE ) ) RETURN IF( TICKTCOUNT >= 3, TICKTCOUNT, 0 )________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon on the right if you like this reply 🙂
- ishanjainFrequent Visitor
This is the error I get in yellow.
- Fowmy
Super User
ishanjain
Try this please:Over 3 Tickets With 30 Days = VAR CURRENT_TICKET = [Ticket ID] VAR CURRENT_DATE = [Despatch Date] VAR MINDATE = MINx( FILTER( VALUES(TICKETS[Despatch Date]), ABS(DATEDIFF(TICKETS[Despatch Date],CURRENT_DATE,DAY))<=30 ), TICKETS[Despatch Date] ) VAR MAXDATE = MAXx( FILTER( VALUES(TICKETS[Despatch Date]), ABS(DATEDIFF(TICKETS[Despatch Date],CURRENT_DATE,DAY))<=30 ), TICKETS[Despatch Date] ) VAR TICKTCOUNT = COUNTROWS( FILTER( TICKETS, TICKETS[Ticket ID]=CURRENT_TICKET && TICKETS[Despatch Date]>=MINDATE && TICKETS[Despatch Date]<=MAXDATE ) ) RETURN IF( TICKTCOUNT >= 3, TICKTCOUNT, 0 )________________________
Did I answer your question? Mark this post as a solution, this will help others!.
Click on the Thumbs-Up icon on the right if you like this reply 🙂