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
jcawley
Helper III
Helper III

Max Date Prior to a Filtered Range?

Hello,

 

I'm trying to see how many customers have came in during the last month (or any filtered range really) that have a completed appointment, who have purchased something previously from us, and who have not been into our office in the last 365 days (relative to any filtered date range).

 

I have two tables. One table (1) shows all customers who have purchased an item, and another table (2) which shows all the dates in which a customer has come to the store.

Table 1

ID
12345
23456

 

Table 2

IDTypeDateCompleted
12345CheckUp06/01/2014Yes
12345CheckUp06/28/2020Yes
23456CheckUp06/01/2014Yes
23457CheckUp06/01/2020No


So far I tried to use the following as suggested by @AllisonKennedy:

Previous Visit Date = MAXX(FILTER(Table2, Table2[Date]<EARLIER(Table2[Date])),Table2[Date])
 - I can't seem to get this to spit out the correct info. It gives dates, but it doesn't seem to be specific to ID
 
Purchased = IF(COUNTROWS(RELATEDTABLE(Table1))>0,"Yes","No")
 
Then create a MEASURE to determine if they are your key client or not: 
KeyClient = IF(DATEDIFF(SELECTEDVALUE(Table2[Previous Visit Date]),MIN(DimDate[Date]),DAY)>365&&SELECTEDVALUE(Table2[Completed])="Yes" && SELECTEDVALUE(Table2[Purchased])="Yes","Yes", "No")

  - Can't get this measure to give me a count!


Any help would be greatly apprecaited!

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

Also, sorry I thought I had updated it, but try this updated version of Previous Visit Date that checks for ID:
Previous Visit Date = MAXX(FILTER(Table2, Table2[ID]=EARLIER(Table2[ID]) &&Table2[Date]<EARLIER(Table2[Date])),Table2[Date])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

2 REPLIES 2
AllisonKennedy
Super User
Super User

Also, sorry I thought I had updated it, but try this updated version of Previous Visit Date that checks for ID:
Previous Visit Date = MAXX(FILTER(Table2, Table2[ID]=EARLIER(Table2[ID]) &&Table2[Date]<EARLIER(Table2[Date])),Table2[Date])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

AllisonKennedy
Super User
Super User

Can you provide a sample of your desired output? The measure I suggested works if you have ID in the visual, but if you're not going to have ID in that visual you could try a variation of what I suggested in your other post, only using a COUNTROWS(FILTER(Table1, ...

You'll need to slightly ammend the filter functions accordingly to get them to talk to the Table1 data based on your relationships. You also won't need the filter for Purchased="Yes" since Table1 already does that for you.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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.