Home > front end >  COUNTIFS in M language over two tables
COUNTIFS in M language over two tables

Time:01-12

My objective is to determine whether certain users have been set up correctly in the finance system.

To determine this, I have a table of users showing their name, team, specific finance role and their permissions, similar to this:
Table name: USERS

| User       | Team | ApprovalRole | UserGroup        |
| ----       | ---- | ------------ | ---------        |
| User One   | ABC  | <75K         | APPROVER         |
| User Two   | ABC  | <1M          | APPROVER         |
| User Three | ABC  | <500K        | BASIC            |
| User Four  | TRD  | POA-1,000    | PO APPROVER      |
| User Five  | TRD  | POA-50,000   | PO APPROVER      |
| User Six   | ZBQ  | INV_APP      | INVOICE APPROVER |
| User Seven | ZBQ  | 0            | BASIC            |
| User Eight | YHW  | 0            | BASIC            |
| User Nine  | YHW  | CEO          | BASIC            |
| User Ten   | YHW  | INVAPP       | INVOICE APPROVER |

I also have a lookup-table which lists the "correct" set-up of the roles which I'm monitoring. Below is a sample table showing the structure:
Table name: LOOKUPS

| RoleName         | Team | ApprovalRole | UserGroup        |
| --------         | ---- | ------------ | ---------        |
| PO Approver      | ABC  | <            | Approver         |
| PO Approver      | TRD  | POA-         | PO Approver      |
| PO Approver      | ZBQ  | CEO          | Approver         |
| Invoice Approver | ZBQ  | INV_APP      | Invoice Approver |
| Invoice Approver | YHW  | INVAPP       | Invoice Approver |

My end-goal is to have a column added to USERS table which identifies whether these types of users are set-up correctly.

APPROACH 1
My preferred approach would be like a COUNTIFS in Excel.
SUM(COUNTIFS(LOOKUPS[Team],[@Team],LOOKUPS[ApprovalRole],[@ApprovalRole]),COUNTIFS(LOOKUPS[Team],[@Team],LOOKUPS[UserGroup],[@UserGroup])).
This will give a score of 0, 1 or 2:

  • 0's I can ignore - they aren't connected to this activity at all;
  • 1's are errors. They either have the ApprovalRole OR they have the UserGroup, but not both. These need to be fixed;
  • 2's are passes - everything is fine so nothing to worry about.

Q1: If I go down this route, can someone provide some help on how best to code these formulae in M language? I've tried to follow the post from enter image description here

  •  Tags:  
  • Related