ifna formula in Power Query - replace multiple/alternate vlookup

blackduck

New Member
Joined
Sep 27, 2017
Messages
7
Hi,
I have some formula's that I am trying to replace using Power Query.... not sure what the best way to explain this is but I will explain the scenario in excel first. I need to look at column 1 and return the value specified in the lookup table, but if the number doesn't exist in column 1 lookup table, I want to lookup column 2 and return the value based on the lookup table. The formula I am using to do this is: =IFNA(VLOOKUP(A2,A10:C15,3,0),VLOOKUP(B2,B10:C15,2,0))

EXAMPLE DATA with last column being what i want to be generated by the formula:
Column 1Column 2RETURNED VALUES
1dblue
2ered
3fyellow
4dgreen
5eorange
6fblack


<tbody>
</tbody>


LOOKUP TABLE:
Column 1Column 2Result
1blue
2red
3yellow
dgreen
eorange
fblack

<tbody>
</tbody>



Does anyone have any ideas how to do this in Power Query? And can Power Query return a certain value if no matches are received at all? I know how to merge tables as a replacement for standard vlookups but have no idea how to do a complicated lookup. Any help would be greatly appreciated!!!!!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You could do a double merge and then test which returned table is empty?

Code:
let
    DataTable = Excel.CurrentWorkbook(){[Name="DataTable"]}[Content],


    LookupTable = Excel.CurrentWorkbook(){[Name="LookupTable"]}[Content],


    Merge1 = Table.NestedJoin(DataTable,
                              "Column 1",
                              LookupTable,
                              "Column 1",
                               "Merge1",
                               JoinKind.LeftOuter
                              ),


    Merge2 = Table.NestedJoin(Merge1,
                              "Column 2",
                              LookupTable,
                              "Column 2",
                              "Merge2",
                               JoinKind.LeftOuter
                             ),


    FinalTable = Table.AddColumn(Merge2,
                                 "RESULT",
                                 each if 
                                         Table.IsEmpty([Merge1])
                                      then
                                          if 
                                             Table.IsEmpty([Merge2]) 
                                          then 
                                             "No Matches" 
                                          else 
                                              Record.Field([Merge2]{0},"Result")
                                      else
                                          Record.Field([Merge2]{0},"Result"),
                                   type text)
in
    FinalTable



 
Last edited:
Upvote 0
Code:
let
    Lookup = Excel.CurrentWorkbook(){[Name="LookupTable"]}[Content],
    DataTbl = Excel.CurrentWorkbook(){[Name="DataTable"]}[Content],
    #"Added Custom" = Table.AddColumn(DataTbl, "Returned Values", each try Lookup{[Column 1 = [Column 1]]}[Result] otherwise Lookup{[Column 2 = [Column 2]]}[Result])
in
    #"Added Custom"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,042
Members
448,940
Latest member
mdusw

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