Forum Discussion
Lookup a value in other table - DAX
I have a table A with duplicate values in one column. I want to run a vlookup in another table B, and want to return 'TRUE' if it exists in table A. eg below-
TABLE A ::
ID amount
1 10
2 15
1 25
3 38
TABLE B ::
1 TRUE
4 FALSE
Someone please help ASAP. Thanks a ton!
Abhishek
12 Replies
- Zubair_Muhammad
Community Champion
Hi, Try this calculated column
=calculate(countrows(tableA), filter(tableA, tableA[I'd] =tableB[I'd])) >0- nickchobotar
Skilled Sharer
- Zubair_Muhammad
Community Champion
Hi nickchobotar
If abhitiwa wants to just check if ID exists then it should be >0
Else if he is checking for duplicates then it should be>1
- AnonymousNot applicable
HI abhitiwa,
You can add a calculated column with below formula to check exist item based on other table:
Check = [ID] in VALUES(Records[ID])
Regards,
Xiaoxin Sheng
- nickchobotar
Skilled Sharer
Anonymous
That's great. Another way is to wrap VALUES() into a CALCULATE() for context transition.
*** works with relationship only, though
- drewlewis15
Solution Specialist
One way to do this would be:
- Start on Table B within your Query Editor
- Choose Merge Queries on the Home tab and select Table A as the table to merge, selecting ID as the relationship
- Join Kind = Left Outer
- This will return a new column into Table B called "TABLE A"
- Add a custom column with this statement: if Table.First([TABLE A]) = null then "FALSE" else "TRUE"
- Delete the "TABLE A" column, and your table should now look like this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMlGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [ID = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type",{"ID"},#"TABLE A",{"ID"},"TABLE A",JoinKind.LeftOuter),
#"Added Custom" = Table.AddColumn(#"Merged Queries", "Match", each if Table.First([TABLE A]) = null then "FALSE" else "TRUE"),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"TABLE A"})
in
#"Removed Columns"