Forum Discussion

DeeA's avatar
DeeA
Frequent Visitor
2 years ago

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 below

 

2. For every month how do i show in a visual the count of movement like below;

 A distinct cities visited of 1 means static

 

 

Thanks

 

 

 

3 Replies

  • Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
    https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216

     

    Please note that Oklahoma is a state, not a city.
    Please show the expected outcome based on the sample data you provided.

    https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Anonymous's avatar
    Anonymous
    Not 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's avatar
      DeeA
      Frequent 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 period

      2. 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