Forum Discussion
DeeA
2 years agoFrequent Visitor
DIstinct count based on multiple conditons
Hi parry2k, Can you please assist; I have a table that looks like below; I want to be able to 1. countdistinct the number of cities per customer for each month for an output similar to b...
Anonymous
2 years agoNot applicable
Hi DeeA ,
Here are the steps you can follow:
Question1:
1. Create measure.
Result1 =
COUNTX(
FILTER(ALL('Table'),
'Table'[Month]=MAX('Table'[Month])&&'Table'[Customer]=MAX('Table'[Customer])),[Cities visited])
2. Result:
Question2:
1. Enter data – create a flag table.
2. Create measure.
Result2 =
SWITCH(
TRUE(),
MAX('Move_Table'[Group])="Static",
CALCULATE(DISTINCTCOUNT('Table'[Customer]),
FILTER(ALL('Table'),'Table'[Month]=MAX('Table'[Month])&&[Result1]=0)),
MAX('Move_Table'[Group])="Move 2 times",
CALCULATE(DISTINCTCOUNT('Table'[Customer]),
FILTER(ALL('Table'),'Table'[Month]=MAX('Table'[Month])&&[Result1]=2)),
MAX('Move_Table'[Group])="Move 3 times",
CALCULATE(DISTINCTCOUNT('Table'[Customer]),
FILTER(ALL('Table'),'Table'[Month]=MAX('Table'[Month])&&[Result1]=3)),
MAX('Move_Table'[Group])="Move 4 times",
CALCULATE(DISTINCTCOUNT('Table'[Customer]),
FILTER(ALL('Table'),'Table'[Month]=MAX('Table'[Month])&&[Result1]=4)),
MAX('Move_Table'[Group])="Move 5 times",
CALCULATE(DISTINCTCOUNT('Table'[Customer]),
FILTER(ALL('Table'),'Table'[Month]=MAX('Table'[Month])&&[Result1]=5)))
3. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
DeeA
2 years agoFrequent Visitor
Thanks a lot.
For Result1 i used the below;
Distinct regions = CALCULATE(
DISTINCTCOUNT('Table'[city]),
ALLEXCEPT('Table', 'Table'[customer], 'Table'[Mth])
)
which worked well..gave me the distinct number of cities the customers visited over the 8month period2. a little modification to your second solution (result2) worked perfectly for me. However my table has 8 months. how do i modify the filter condition so that it considers all the months and not give me the results for just the maximum month. so that i can categorise (move 2 times, move 3 times, ..., move n times) for the distinct cities for all the customers over the 8 month period.
Thanks