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
Anonymous
Not applicable

Showing latest date before specific date

Hi all

 

I am trying only to show the client's latest ticket date if it's older than two weeks using DAX.

 

For example, today is the 21st and 2 weeks ago it was the 7th, I only want to show the clients where there latest ticket was on or before the 7th, SS for the structure:

Housden96_0-1671636984682.png

The Latest ticket field is a date field set to the latest.

 

I have tried multiple methods, using Dax, as this has to be dynamic and based on today's date. 

 

I have seen multiple methods online trying to set the latest ticket to show as 1 in another column using an IF statement but so far none seem to work am I missing something here?

 

Thanks in advance

 

1 ACCEPTED SOLUTION

Thank you for sample data. Here is the code:

Customers with last ticket older than 2 weeks ago = 
var customer_last_ticket =
    MAXX(
        DISTINCT('Sample'[client_id]);
        MAX('Sample'[created_at])
    )
return IF(DATEDIFF(customer_last_ticket;TODAY();DAY)>=14;customer_last_ticket)

bolfri_1-1671665063197.png

In the variable customer_last_ticket we are storing an information about last ticket per customer

Then if this ticket is older than 14 days ago we are displaying int 🙂

 

I hope that this is what you've wanted.

 





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

Proud to be a Super User!




View solution in original post

16 REPLIES 16
bolfri
Super User
Super User

Try this one. 🙂
 
Lastticket older than 2 weeks ago =
MAXX(
    FILTER('Sample';DATEDIFF('Sample'[DateTime];TODAY();DAY)>=14);
    'Sample'[DateTime]
)

bolfri_0-1671644206955.png

 





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

Proud to be a Super User!




Anonymous
Not applicable

So this has worked but not exactly how I want it to work. 

It pulls in each client's ticket from two weeks ago or from the last time two weeks ago. 
But I would like to exclude clients where they have put recent tickets in.

The concept is to detect inactive clients on a support desk. 

 

I have no idea why I am struggling with this so much when I know how to do it within Tableau :').

Your sample shows only one date per custmer, so I was assuming that in this column you have only one, last datetime to each customer. If you have multiple values in this column for each customer then you should put another sample data with such records and describe which customer you want to include or exlude. It will be easier.





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

Proud to be a Super User!




Anonymous
Not applicable

Test data is attached.

 

So for this example, the correct result would show client 171 and client 197 as follows (using - as table break line):

 

Client - Created_at

171    - 20/10/2022

197    - 08/11/2022

 

And not clients 1 and 34 due to having tickets past the 7th.

 

client_idcreated_at
3430/11/2022 10:23
3401/12/2022 10:20
3401/12/2022 15:17
3401/12/2022 16:11
3402/12/2022 11:32
3402/12/2022 14:56
3402/12/2022 16:38
3405/12/2022 13:11
3405/12/2022 13:11
3406/12/2022 09:47
3407/12/2022 09:14
3408/12/2022 15:41
3409/12/2022 08:59
3409/12/2022 11:41
3409/12/2022 15:23
3409/12/2022 16:14
3409/12/2022 16:17
3409/12/2022 16:53
3412/12/2022 13:44
3413/12/2022 08:39
3414/12/2022 08:44
3414/12/2022 11:29
3415/12/2022 10:27
3416/12/2022 15:23
3419/12/2022 12:11
3419/12/2022 12:11
3419/12/2022 16:50
3421/12/2022 09:49
123/11/2022 12:53
123/11/2022 17:32
124/11/2022 05:08
124/11/2022 09:26
124/11/2022 09:26
124/11/2022 10:35
124/11/2022 15:26
125/11/2022 10:17
125/11/2022 10:19
125/11/2022 11:02
125/11/2022 12:02
128/11/2022 04:30
128/11/2022 04:31
128/11/2022 08:02
128/11/2022 10:02
128/11/2022 10:14
128/11/2022 11:14
128/11/2022 12:05
129/11/2022 09:44
129/11/2022 10:47
129/11/2022 14:10
129/11/2022 15:11
129/11/2022 15:20
129/11/2022 15:59
130/11/2022 10:02
130/11/2022 11:39
130/11/2022 11:54
130/11/2022 12:03
130/11/2022 14:11
130/11/2022 15:41
130/11/2022 15:47
101/12/2022 10:02
101/12/2022 10:48
101/12/2022 13:41
101/12/2022 14:29
102/12/2022 00:02
102/12/2022 00:07
102/12/2022 00:08
102/12/2022 12:02
103/12/2022 11:02
104/12/2022 22:09
105/12/2022 04:30
105/12/2022 08:02
105/12/2022 09:02
105/12/2022 10:02
105/12/2022 12:31
105/12/2022 12:49
105/12/2022 12:49
105/12/2022 13:00
105/12/2022 13:20
105/12/2022 14:35
106/12/2022 09:53
106/12/2022 12:02
106/12/2022 12:20
106/12/2022 13:23
107/12/2022 03:44
107/12/2022 10:05
113/12/2022 14:44
113/12/2022 15:15
113/12/2022 15:17
113/12/2022 16:55
113/12/2022 16:55
114/12/2022 08:58
119/12/2022 04:30
119/12/2022 08:02
119/12/2022 10:02
119/12/2022 12:35
120/12/2022 11:46
120/12/2022 13:35
120/12/2022 14:29
120/12/2022 15:46
120/12/2022 15:50
120/12/2022 16:38
120/12/2022 17:11
120/12/2022 17:23
120/12/2022 17:59
121/12/2022 13:35
121/12/2022 18:36
17121/03/2022 16:58
17123/03/2022 11:07
17120/04/2022 10:28
17116/05/2022 11:22
17127/06/2022 09:40
17107/07/2022 11:22
17112/07/2022 13:28
17114/07/2022 12:58
17126/07/2022 17:34
17119/08/2022 09:04
17101/09/2022 15:16
17106/09/2022 10:13
17108/09/2022 11:25
17127/09/2022 13:40
17120/10/2022 14:32
19720/09/2022 13:10
19720/09/2022 13:34
19720/09/2022 13:37
19720/09/2022 13:43
19720/09/2022 14:10
19720/09/2022 14:19
19726/09/2022 13:18
19731/10/2022 12:02
19708/11/2022 14:12

Thank you for sample data. Here is the code:

Customers with last ticket older than 2 weeks ago = 
var customer_last_ticket =
    MAXX(
        DISTINCT('Sample'[client_id]);
        MAX('Sample'[created_at])
    )
return IF(DATEDIFF(customer_last_ticket;TODAY();DAY)>=14;customer_last_ticket)

bolfri_1-1671665063197.png

In the variable customer_last_ticket we are storing an information about last ticket per customer

Then if this ticket is older than 14 days ago we are displaying int 🙂

 

I hope that this is what you've wanted.

 





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

Proud to be a Super User!




Anonymous
Not applicable

Okay this has worked thank you so much!! I removed and re-added the data and it started working as expected much appreciated!!!

Anonymous
Not applicable

Just tried this again and still no luck sadly! I am glad to see it works for you with the test date bellow is a screenshot of what I have done with DB names covered:

Housden96_0-1671704842852.png

I have client_id set as a whole number and created_at set as date time, does this reflect your structure within the test data?

The data is being pulled in from SQL on my end.

I don't think so. Can you paste here an example data rows for customer 0?





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

Proud to be a Super User!




Anonymous
Not applicable

Sorry, it's just another client number so the data would be roughly the same as the test data supplied.

 

Tried to attach a test file but cannot link any more.

 

Are you developing this as a measure or column?

 

This code that I've send you is a measure.





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

Proud to be a Super User!




johnt75
Super User
Super User

Try 

Latest Ticket =
VAR LastTicket =
    MAX ( 'Table'[Ticket time] )
RETURN
    IF ( LastTicket <= ( TODAY () - 14 + TIME ( 23, 59, 59 ) ), LastTicket )
Anonymous
Not applicable

Just tried and unfortunatly it doesnt work.

in what way? what values is it returning, or is it not returning any values ?

Anonymous
Not applicable

Appolagies that was super vauge.

Its showing no values:

Housden96_0-1671641016719.png

 

It works in my sample. Double check that the column which has the datetime in it is set as type datetime, both in Power Query and in Power BI desktop. If it was type text or something then that might explain it.

Anonymous
Not applicable

Just checked and both are date time.

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.