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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
EvertonRamone
Helper I
Helper I

DAX Measure if customer bought some product

I need a DAX measure wich shows me a flag (1 or 0) if a customer bought the product "A" someday (for the first time) and later have bought product "C"

 

Measure1: Flag (1 or 0) in the customer name side if bought

Measure2: When was the first time that he bought product C

 

Example1.PNG

 

If need, here are the tables:

KeyDateKeyCustomerKeyProductTotal
11112,9
12213
131156,4
141564,8
211894,8
22156,5
313564,85
323564,8
4121325,6
422132,3

 

KeyProductProduct
1A
2B
3C

 

 

KeyCustomerName
1Jean
2Mari
3Lisa
4Julian

 

Calendar
KeyDateDate
101/01/2018
202/01/2018
303/01/2018
404/01/2018

 

 

Can someone help me?

 

Att..

1 ACCEPTED SOLUTION
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @EvertonRamone,

Based on my test, you could refer to below formula:

Measure1Flag = IF(CALCULATE(DISTINCTCOUNT(FactSales[KeyProduct]),FILTER(ALL(FactSales),(FactSales[KeyProduct]=1 || FactSales[KeyProduct]=3 )&&FactSales[KeyCustomer]=MAX(FactSales[KeyCustomer])))=2,
         CALCULATE(DISTINCTCOUNT(Customer[KeyCustomer]),FILTER(FactSales,(FactSales[KeyProduct]=1 ||FactSales[KeyProduct] = 3)&& FactSales[KeyCustomer] = MAX(FactSales[KeyCustomer]))),
         0)
FirstTimeBoughtProductC = CALCULATE(MAX('Calender'[Date]),FILTER(ALL('Calender'),'FactSales'[Measure1Flag]<>0))

Result:

1.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/vuzdj6shen674dn/ZZZZZ.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @EvertonRamone,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Microsoft Employee
Microsoft Employee

Hi @EvertonRamone,

Based on my test, you could refer to below formula:

Measure1Flag = IF(CALCULATE(DISTINCTCOUNT(FactSales[KeyProduct]),FILTER(ALL(FactSales),(FactSales[KeyProduct]=1 || FactSales[KeyProduct]=3 )&&FactSales[KeyCustomer]=MAX(FactSales[KeyCustomer])))=2,
         CALCULATE(DISTINCTCOUNT(Customer[KeyCustomer]),FILTER(FactSales,(FactSales[KeyProduct]=1 ||FactSales[KeyProduct] = 3)&& FactSales[KeyCustomer] = MAX(FactSales[KeyCustomer]))),
         0)
FirstTimeBoughtProductC = CALCULATE(MAX('Calender'[Date]),FILTER(ALL('Calender'),'FactSales'[Measure1Flag]<>0))

Result:

1.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/vuzdj6shen674dn/ZZZZZ.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@EvertonRamone not sure if I exactly get your question.

 

Do you want value 1 if a customer bought product A before product C

OR

Do you want value 1 if a customer bought product A and product C

 

Here are some options you can mix and match to get both the above

 

For the first date when a customer bought A or C you can use the formula 

FirstDateBoughtC = CALCULATE(MIN(Date[Date]), ALLEXCEPT(FactSales, FactSales[KeyCustomer]), FILTER(Product, Product[Product] = "C"))

FirstDateBoughtA = CALCULATE(MIN(Date[Date]), ALLEXCEPT(FactSales, FactSales[KeyCustomer]), FILTER(Product, Product[Product] = "A"))

 

 

Measure = SWITCH(TRUE(),

                                FirstDateBoughtA < FirstDateBoughtC && FirstDateBoughtA <> NULL && FirstDateBoughtC <> NULL,1

                                ......some condition, 1/0,

                                0)

         

 

 

 

 

 

 

@Anonymous, I want value 1 if customer bought product "A "someday (before buying product C) and then later bought product C

Anonymous
Not applicable

@EvertonRamone try the formulae in my above comment and that should do the trick.

@Anonymous, It didn't work... My fact table and date table have the relashionship set to filter only one direction, not both... I think that this is the reason why isn't working. Is there any other way?

Anonymous
Not applicable

@EvertonRamone it should work, can you plz post your power bi file here so i can check whats going on here.

 

also if u cant share the data feel free to create one with dummy data.

 

to post file post it to dropbox or google drive and paste the link here.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.