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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JamesH2405
Frequent Visitor

When index is -1 return X

hi all,

I am very new to all of this so please excuse my lack of knoweldge, i am just starting out learning Bi and DAX etc.

i was self taught on excel and created a formula to lookup from a list then if the value doesnt exist to insert "X"

now, ive worked out how to index in power query and that if the value doesnt exist it returns -1, but how do i get the lookup value to insert "X" if the index is -1?

 

Excel Formula 

=IF(OR(E2=""),"LOCAL",IF(ISNA(VLOOKUP(E2,Sheet1!$A$2:$B$65,2,0)),"LOCAL",VLOOKUP(E2,Sheet1!$A$2:$B$65,2,0)))

 

DAX

= Table.AddColumn(#"Changed Type3", "Customer", each Customer[Name]{List.PositionOf(Customer[Customer Number],[Customer number])})

 

JamesH2405_0-1681736180894.png

 

any help would be amazing 🙂

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JamesH2405 ,

 

Click "Advanced Editor" to copy and paste the following code, and check the steps on the right.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUUpMUorViVZyAjJTU8BMkGhaCly0OBHMdAGpLQYznYHMlFS4KFStG1RBLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CustomerName = _t, Other = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CustomerName", type text}, {"Other", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"CustomerName"}, Table1, {"CustomerName"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"CustomerID"}, {"Table1.CustomerID"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Table1", "Custom", each if [Table1.CustomerID] = null then "Local" else if [Table1.CustomerID] <> null then [Table1.CustomerID] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Table1.CustomerID"})
in
    #"Removed Columns"

vtangjiemsft_0-1681873329392.png

 

Or you can also use the LOOKUPVALUE() function in desktop.

Measure = 
var _a=LOOKUPVALUE('Table'[value],'Table'[type],MAX('Table (2)'[type]))
return IF(_a=BLANK(),"Local",_a)

vtangjiemsft_1-1681873367060.png

Please refer to the following documents for more information.

How to Perform VLOOKUP in Power Query in Excel - A Step by Step Guide (excelchamps.com)

DAX In Power BI - How To Use LOOKUPVALUE() Function (c-sharpcorner.com)

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @JamesH2405 ,

 

Click "Advanced Editor" to copy and paste the following code, and check the steps on the right.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUUpMUorViVZyAjJTU8BMkGhaCly0OBHMdAGpLQYznYHMlFS4KFStG1RBLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [CustomerName = _t, Other = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CustomerName", type text}, {"Other", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"CustomerName"}, Table1, {"CustomerName"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"CustomerID"}, {"Table1.CustomerID"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded Table1", "Custom", each if [Table1.CustomerID] = null then "Local" else if [Table1.CustomerID] <> null then [Table1.CustomerID] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Table1.CustomerID"})
in
    #"Removed Columns"

vtangjiemsft_0-1681873329392.png

 

Or you can also use the LOOKUPVALUE() function in desktop.

Measure = 
var _a=LOOKUPVALUE('Table'[value],'Table'[type],MAX('Table (2)'[type]))
return IF(_a=BLANK(),"Local",_a)

vtangjiemsft_1-1681873367060.png

Please refer to the following documents for more information.

How to Perform VLOOKUP in Power Query in Excel - A Step by Step Guide (excelchamps.com)

DAX In Power BI - How To Use LOOKUPVALUE() Function (c-sharpcorner.com)

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

thats amazing, just what i needed, 

im still very new to all of this and self learning so its all very fresh 🙂

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.