vlookup with countifs and isnumber to power query

fayez_MrExcel

Active Member
Joined
Oct 29, 2005
Messages
444
Office Version
  1. 365
Platform
  1. Windows
Im new in Power query, i'd like to convert my excel formula in power query (adding custom column). Basically, if the position has *contractor" in it, then value is "Contractor". if the position code appears in the supervisor column, if so then return value as "Supervisory" otherwise "Individual Contributor"

Book1
ABCD
1PositionPosition TitleSupervisorJob Level
250083048Section Head, Network & Unified Coms50087289Supervisor
350089906Manager, HDPE50086143Individual Contributor
450084476Chief Information Officer50090211Supervisor
550087059Supt, Operation - PP50089908Individual Contributor
650087256Manager, HRBP Corporate Functions50084475Individual Contributor
750087289Manager, Infrastructure & Operations50084476Supervisor
850090918Contractor Online50086575Contractor
950086622Geo Contractor50086634Contractor
105008668850083048Individual Contributor
ZORG
Cell Formulas
RangeFormula
D2:D10D2=IF(COUNTIFS([@[Position Title]],"*Contractor*"),"Contractor",IF(ISNUMBER(MATCH([@Position]&"",[Supervisor]&"",0)),"Supervisor","Individual Contributor"))
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
How about this?

PQ
ABCD
1PositionPosition TitleSupervisorJob Level
250083048Section Head, Network & Unified Coms50087289Supervisor
350089906Manager, HDPE50086143Individual Contractor
450084476Chief Information Officer50090211Supervisor
550087059Supt, Operation - PP50089908Individual Contractor
650087256Manager, HRBP Corporate Functions50084475Individual Contractor
750087289Manager, Infrastructure & Operations50084476Supervisor
850090918Contractor Online50086575Contractor
950086622Geo Contractor50086634Contractor
105008668850083048Individual Contractor
Table3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    JobLevel = Table.AddColumn(
        Source, "Job Level", 
        each try 
            if Text.Contains([Position Title],"Contractor") then "Contractor" 
            else if List.Contains(Source[Supervisor],[Position]) then "Supervisor" 
            else "Individual Contractor" 
        otherwise "Individual Contractor"
    )
in
    JobLevel
 
Upvote 0
How about this?

PQ
ABCD
1PositionPosition TitleSupervisorJob Level
250083048Section Head, Network & Unified Coms50087289Supervisor
350089906Manager, HDPE50086143Individual Contractor
450084476Chief Information Officer50090211Supervisor
550087059Supt, Operation - PP50089908Individual Contractor
650087256Manager, HRBP Corporate Functions50084475Individual Contractor
750087289Manager, Infrastructure & Operations50084476Supervisor
850090918Contractor Online50086575Contractor
950086622Geo Contractor50086634Contractor
105008668850083048Individual Contractor
Table3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    JobLevel = Table.AddColumn(
        Source, "Job Level",
        each try
            if Text.Contains([Position Title],"Contractor") then "Contractor"
            else if List.Contains(Source[Supervisor],[Position]) then "Supervisor"
            else "Individual Contractor"
        otherwise "Individual Contractor"
    )
in
    JobLevel

lrobbo314

How about this?

PQ
ABCD
1PositionPosition TitleSupervisorJob Level
250083048Section Head, Network & Unified Coms50087289Supervisor
350089906Manager, HDPE50086143Individual Contractor
450084476Chief Information Officer50090211Supervisor
550087059Supt, Operation - PP50089908Individual Contractor
650087256Manager, HRBP Corporate Functions50084475Individual Contractor
750087289Manager, Infrastructure & Operations50084476Supervisor
850090918Contractor Online50086575Contractor
950086622Geo Contractor50086634Contractor
105008668850083048Individual Contractor
Table3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    JobLevel = Table.AddColumn(
        Source, "Job Level",
        each try
            if Text.Contains([Position Title],"Contractor") then "Contractor"
            else if List.Contains(Source[Supervisor],[Position]) then "Supervisor"
            else "Individual Contractor"
        otherwise "Individual Contractor"
    )
in
    JobLevel

How about this?

PQ
ABCD
1PositionPosition TitleSupervisorJob Level
250083048Section Head, Network & Unified Coms50087289Supervisor
350089906Manager, HDPE50086143Individual Contractor
450084476Chief Information Officer50090211Supervisor
550087059Supt, Operation - PP50089908Individual Contractor
650087256Manager, HRBP Corporate Functions50084475Individual Contractor
750087289Manager, Infrastructure & Operations50084476Supervisor
850090918Contractor Online50086575Contractor
950086622Geo Contractor50086634Contractor
105008668850083048Individual Contractor
Table3


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    JobLevel = Table.AddColumn(
        Source, "Job Level",
        each try
            if Text.Contains([Position Title],"Contractor") then "Contractor"
            else if List.Contains(Source[Supervisor],[Position]) then "Supervisor"
            else "Individual Contractor"
        otherwise "Individual Contractor"
    )
in
    JobLevel

lrobbo314 thank you for the response. However, my table source is within the PQ itself. Im trying to replicate your formula but getting an error.

 

Attachments

  • PQ - query.JPG
    PQ - query.JPG
    181.3 KB · Views: 9
Upvote 0
You're pasting all the code into the add column step.

I don't know what you mean by, my table source is in PQ itself.

If you have some steps already or if you just loaded the table in, you just need to add the JobLevel line of code. The JobLevel line needs to reference whatever the previous step was as the first argument.

So, copy the JobLevel line of code and go to your query. Open the advanced editor. Paste the line of code at the end before the 'in' statement. Make whatever adjustments you need. Make sure you reference the JobLevel step as the last part of the query. e.g.

Power Query:
in
    JobLevel

is how the last 2 lines in the query should look.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top