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
EvertonRamone
Helper I
Helper I

Customers who bought and not bought some product in last 90 days

I need a dax measure wich shows me which customer bought product B and C in last 90 days

And another one wich shows me those whose bought product B and C in last 90 days

 

(based in my filter date context)

 

Below is like it should be:

 

Example1.PNG

 

Can someone help me?

 

Here is a sample data if needed:

 

FactSales   
KeyDateKeyCustomerKeyProductTotal
11112,9
12213
131156,4
141564,8
211894,8
22156,5
312564,85
323564,8
4111325,6
421132,3

 

Customer
KeyCustomerName
1Jean
2Mari
3Lisa
4Julian
5Jhonny

 

Calendar
KeyDateDate
101/01/2018
202/01/2018
301/05/2018
401/08/2018

 

Product
KeyProductProduct
1A
2B
3C

 

 

1 ACCEPTED SOLUTION

Hi @EvertonRamone

I made some change to my previous solution.

Still add the "date" column from my created date table to the slicer, but set the slicer as "list" mode.

Then create a measure in the date table

Measure = DATEADD('Table'[Date],-90,DAY)

when you select "2018/8/1" in the slicer, the measure would show the 90 days before the "2018/8/1".

Then modify the measure bought last 90 days as below

bought last 90 days = IF(MAX([date])>=[Measure]&&MAX([date])<=MAX('Table'[Date]),1,0)

13.png

 

Best Regards

Maggie

 

View solution in original post

5 REPLIES 5
v-juanli-msft
Community Support
Community Support

Hi @EvertonRamone

1.Create a date table

Table = CALENDAR(DATE(2018,1,1),DATE(2018,12,31))

according to the dataset, DATE(2018,1,1) should be the min date, DATE(2018,12,31) should be the max date. 
You could modify them for your real dataset.

2.Create relationship between the date table and Calendar table

5.png

3. add the "date" column to a slicer, and select "relative" ->"Last","90",'Days"

6.png

4.png

4. Create a calculated column in the FactSales table

date = RELATED('Calendar'[Date])

5. Then create measures

bought last 90 days = IF(MAX([date])>=MIN('Table'[Date]),1,0)

bought B,C = IF(MAX([KeyProduct])=2||MAX([KeyProduct])=3,1,0)

if bought = IF([bought B,C]=1&&[bought last 90 days]=1,1,0)

count bought = CALCULATE(COUNT(Customer[Name]),FILTER(ALL(Customer),[if bought]=1))

count not bought = CALCULATE(COUNT(Customer[Name]),FILTER(ALL(Customer),[if bought]=0))

7.png

 

Best Regards

Maggie

@v-juanli-msft
I can't use this case.

When the user filter a date, example: 01/06/2018

The measure must look 90 days back and check in fact table if that custuomer appeared and bought product B or C, then 1 if yes and 0 if doesn't


I did something like this;

CALCULATE (
DISTINCTCOUNT(
Customer[CustomerKey);
DimProduct[Product] in {"A"; "B"}
FILTER(DimDate; DimDate[Date] >= MAX(DimDate[Date])-90 && DimDate[Date] <> MAX(DimDate[Date]))
)

But the problem is being looking back, it is not taking 90 days before the filter and is calculating wrong

Hi @EvertonRamone

I made some change to my previous solution.

Still add the "date" column from my created date table to the slicer, but set the slicer as "list" mode.

Then create a measure in the date table

Measure = DATEADD('Table'[Date],-90,DAY)

when you select "2018/8/1" in the slicer, the measure would show the 90 days before the "2018/8/1".

Then modify the measure bought last 90 days as below

bought last 90 days = IF(MAX([date])>=[Measure]&&MAX([date])<=MAX('Table'[Date]),1,0)

13.png

 

Best Regards

Maggie

 

Anonymous
Not applicable

proposal of  solution -90 days.JPGproposal of  solution.JPG

I do not know how to use dax measure. I would solve it in this way. You can choose the time and then click what you are interested in.

Thanks @Anonymous, but I'll really need a measure like that

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.