Forum Discussion

Spigaw's avatar
Spigaw
Helper III
3 years ago
Solved

COUNTIFS in Power Query (M)

Hi there,   We use a lot of COUNTIFS() in Excel, because we have to extract unique occurrences of employees in order to make sure they don't appear multiple times.   For example, in this table: ...
  • BA_Pete's avatar
    BA_Pete
    3 years ago

     

    OK, so I started from scratch just to make sure I was working through the issue correctly. I've attached the working PBIX at the bottom so I won't post each individual bit of code here.

     

    - Your Days table I didn't do anything with directly, but is used later in a crossjoin.

    - Your Events table I did some pre-prep on to get it looking like this:

     

    - Your Employees table I used as the base for the final process, crossjoining the Dates table and merging the prepped Events table, before double-grouping to generate the daily stats.

    Here's the output:

     

    I think you'd got most of the way here already, so it's probably just the final groupings in the Employees table that are relevant. The first grouping just gets you to a single record per employee/date so you're not double-counting. The second grouping uses custom List.Counts to pick out the stats you're after.

     

    Pete