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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
yacine_Big
Frequent Visitor

Calculate loyal customers

Hi
i need help, i will try to explain my problem i hope someone can understand
i have a table with many costumers and many products
situation number one:
a costumer who buys many products in same category, let's say he buys milk from a brand and another brand too so we can say he is not loyal to a brand he buys whatever milk he find on market
situation number two:
customers who buy only one brand of milk so he is loyal to that brand he only buys that brand and if he doesn't find it on the market, he doesn't buy anything else

i want to calculate the costumer who bought only one brand and no other and calculate too the ones who buys many brand
PS: milk is just an exemple we have many products and many categories.
excuse my english 
Best Regards.

ID Name   -  category    -    products
1 jhon          milk                milk brand 1
1 jhon          milk                milk brand 2
1 mary         milk                milk brand 1
1 mary         milk                milk brand 1
1 jhon          milk                milk brand 2
1 jhon          milk                milk brand 2
1 mary         milk                milk brand 1
1 mary         milk                milk brand 1
1 jhon          milk                 milk brand 3

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@yacine_Big 

maybe you can create a new column

loyalty = if(CALCULATE(DISTINCTCOUNT('Table'[products]),ALLEXCEPT('Table','Table'[ID Name],'Table'[category]))=1,"Y","N")

1.PNG





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

Proud to be a Super User!




View solution in original post

5 REPLIES 5
Ahmedx
Super User
Super User

also to calculate the COUNT  you can do this:

 

LoyalCount = SUMX ( FILTER ( VALUES('Table'[Name]), [number of products] = 1 ), 1 )
DisLoyalCount = SUMX ( FILTER ( VALUES('Table'[Name]), [number of products] > 1 ), 1 )

 

Ahmedx
Super User
Super User

I corrected my file, please download it again

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

https://dropmefiles.com/6QKvt
2023-02-15_15-34-47.png

2023-02-15_15-20-03.png2023-02-15_15-22-08.png

ryan_mayu
Super User
Super User

@yacine_Big 

maybe you can create a new column

loyalty = if(CALCULATE(DISTINCTCOUNT('Table'[products]),ALLEXCEPT('Table','Table'[ID Name],'Table'[category]))=1,"Y","N")

1.PNG





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

Proud to be a Super User!




thank you it works like a charm, with some modifications because my table is more complicated than the one gave you but it really works thank you again .

you are welcome





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

Proud to be a Super User!




Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.