Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Solution_b
Frequent Visitor

Create a manager's flag in M-Query

Create a PBI M-query for a 'Yes' or 'No' flags for Is_employee_a manager?

 

I have a table called Employee with column Employee_id, Manager_employee_id and Period.

 

The logic is to identify and flag ("Yes" or "No") based on Employee_Id if the Employee_Id is in the Manager_employee_Id list in the same period?

Pay attention to Employee_Id G123 who was not a manager in previous month (Period 30/11/2023) but has become a manager in the period 31/12/2023. This should flag "No" for 30/11/2023 but "Yes" in 31/12/2023. The same applies to B123 who was a manager in 30/11/2023 but no longer a manager in 31/12/2023. It should flag "Yes" for 30/11/2023 but "No" for 31/12/2023.

see below table

 

Employee_IdManager_employee_IdPeriod
A123C12330/11/2023
B123E12330/11/2023
C123B12330/11/2023
D123E12330/11/2023
E123 30/11/2023
F123C12330/11/2023
G123 30/11/2023
A123C12331/12/2023
B123E12331/12/2023
C123E12331/12/2023
D123E12331/12/2023
E123G12331/12/2023
F123C12331/12/2023
G123 31/12/2023



From the above table to this table below

Employee_IdManager_employee_IdPeriodFlag
A123C12330/11/2023No
B123E12330/11/2023Yes
C123B12330/11/2023Yes
D123E12330/11/2023No
E123 30/11/2023Yes
F123C12330/11/2023No
G123 30/11/2023No
A123C12331/12/2023No
B123E12331/12/2023No
C123E12331/12/2023Yes
D123E12331/12/2023No
E123G12331/12/2023Yes
F123C12331/12/2023No
G123 31/12/2023Yes

 

Please note: I don't want a calculated column for this.

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

You could try something like...

Table.AddColumn(PREVIOUSSTEP, "Flag", each if List.Contains(List.RemoveItems(List.Distinct(Table.SelectRows(PREVIOUSSTEP, (x)=> x[Period] = [Period])[Manager_employee_Id]), {" "}), [Employee_Id]) then "Yes" else "No")




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
jgeddes
Super User
Super User

You could try something like...

Table.AddColumn(PREVIOUSSTEP, "Flag", each if List.Contains(List.RemoveItems(List.Distinct(Table.SelectRows(PREVIOUSSTEP, (x)=> x[Period] = [Period])[Manager_employee_Id]), {" "}), [Employee_Id]) then "Yes" else "No")




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you.
That solved it.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.