Count from Unique Criteria

  • Hello,


    My data is setup in this way:


    Date Day Area Product SalesmanName
    01/07/2021 Thu A1 Prod-1XN Salesman1
    01/07/2021 Thu A1 Prod-1XN Salesman1
    01/07/2021 Thu A1 Prod-1XN Salesman1
    01/07/2021 Thu A1 Prod-1XN Salesman1
    01/07/2021 Thu A1 Prod-1XN Salesman1
    01/07/2021 Thu A2 Prod-1XN Salesman1
    01/07/2021 Thu A2 Prod-1XN Salesman1
    01/07/2021 Thu A2 Prod-1XN Salesman1
    02/07/2021 Thu A1 Prod-1XN Salesman1
    02/07/2021 Thu A1 Prod-1XN Salesman1
    02/07/2021 Thu A1 Prod-1XN Salesman1
    02/07/2021 Thu A1 Prod-1XN Salesman1
    02/07/2021 Thu A1 Prod-1XN Salesman1
    02/07/2021 Thu A2 Prod-1XN Salesman1
    02/07/2021 Thu A2 Prod-1XN Salesman1
    02/07/2021 Thu A2 Prod-1XN Salesman1




    The Cell F2 has Salesman name and in G2, I need a formula, which will count the salesman visits in areas on all dates.


    So in this case, the formula should return 4 (on 1st July, he visited 2 areas, on 2nd July, he visited 2 areas).


    The pivot tables are counting salesman's name and giving me count of 16, which is not the right answer.


    Highly appreciate your help.


    Many thanks

  • Using Power Query, here is the Mcode to solve


    Code
    1. let
    2. Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    3. #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Day", type text}, {"Area", type text}, {"Product", type text}, {"SalesmanName", type text}}),
    4. #"Grouped Rows" = Table.Group(#"Changed Type", {"Date", "SalesmanName"}, {{"Count", each Table.RowCount(Table.Distinct(_)), Int64.Type}})
    5. in
    6. #"Grouped Rows"

    Attached is a file you can follow the steps.


    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").



    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.



    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.



    - Follow this link for an introduction to Power Query functionality.



    - Follow this link for a video which demonstrates how to use Power Query code provided.