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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
subirch
Frequent Visitor

Power Query - Lookup

Hi,

 

How can I have "Is Manager?" column output from the column "Employee Id" and "Manager Id"in power query?

 

Employee IDManager IDIs Manager?
100200No
200200Yes
300200No
400700Yes
500700No
600700No
700700Yes
800400No
900400No
1000400No
1 ACCEPTED SOLUTION
edhans
Super User
Super User

See this code @subirch 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMgKTfvlKsTrRUA6EjEwtBosZYyozAXPMUZSZIolBlZlhCplj0WkB5pkgK7PEFAK6FlUsFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Manager ID" = _t, #"Is Manager?" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", Int64.Type}, {"Manager ID", Int64.Type}}),
    #"Added Is Manager" = 
        Table.AddColumn(
            #"Changed Type", "Is Manager", 
            each if List.Contains(#"Changed Type"[Manager ID], [Employee ID]) then "Yes" else "No")
in
    #"Added Is Manager"

 


It is a straight forward if/then/else construct with one function. The Key is this function: List.Contains(#"Changed Type"[Manager ID], [Employee ID])

It turns the Manager ID into a list, then scans that list to see if the Employee ID is contained in it, returning True or False.

edhans_0-1629075099115.png

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
edhans
Super User
Super User

See this code @subirch 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwUNJRMgKTfvlKsTrRUA6EjEwtBosZYyozAXPMUZSZIolBlZlhCplj0WkB5pkgK7PEFAK6FlUsFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee ID" = _t, #"Manager ID" = _t, #"Is Manager?" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee ID", Int64.Type}, {"Manager ID", Int64.Type}}),
    #"Added Is Manager" = 
        Table.AddColumn(
            #"Changed Type", "Is Manager", 
            each if List.Contains(#"Changed Type"[Manager ID], [Employee ID]) then "Yes" else "No")
in
    #"Added Is Manager"

 


It is a straight forward if/then/else construct with one function. The Key is this function: List.Contains(#"Changed Type"[Manager ID], [Employee ID])

It turns the Manager ID into a list, then scans that list to see if the Employee ID is contained in it, returning True or False.

edhans_0-1629075099115.png

 

How to use M code provided in a blank query:
1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done
5) See this article if you need help using this M code in your model.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
subirch
Frequent Visitor

Hi Jakinta,

 

Below error is appearing, where "Changed Type" is prior step.

Expression.Error: We cannot convert the value "Changed Type" to type Table.
Details:
Value=Changed Type
Type=[Type]

 

Thank you

#"Changed Type" 

Jakinta
Solution Sage
Solution Sage

= Table.AddColumn(  PriorStepName , "Is Manager?", each if List.ContainsAny ( List.Distinct( PriorStepName [#"Manager ID"]),  {[Employee ID]} ) then "Yes" else "No") 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Solution Authors
Top Kudoed Authors