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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How do I retrieve a record from another table if it is contained in a value in the current table?

I am trying to use the Query Editor to check if a value in Table1 contains any value in Table2 (EarningTypes) and then return the matching value when found. Here is the custom M query code I am using:

 

if List.ContainsAny(Text.Split([Trim_null]," "),EarningTypes[Type]) = true then EarningTypes[Type] else ""

 

It returns a result, but the result appears as a "list" item instead of an actual value. 


Anyone know how I can convert the list record into an actual table value alongside of the original data or simply retrieve the matching record in a manner similar to a Merge Query?

4 REPLIES 4
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try this custom column

 

=Text.Combine(List.Intersect({Text.Split([Trim_null]," "),EarningTypes[Type]})," ")

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

That worked perfectly. Unfortunately, I realized after I tried your solution that I was actually wanting to do something slightly different. Currently, my formula splits a string at each occurence of the delimiter. What I actually need is to simply see if a string contains any text that appears as a value in another table and return the matching text.

 

I have tried modifying this on my own using functions such as List.ContainsAny, but I cannot get it to work.

Hi @Anonymous 

 

Could you Copy paste a small dataset with expected results?


Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

@Zubair_Muhammad ,

 

I appreciate all your help and hope the following gives you sufficient information.

 

This is the OriginalImport table:

 

CSV String
                      001 Category A    11.11    13.121     1,232.11       1,125.15     Type C      145.21       1,641.85 
      005 Category B        150    2.62       311.24         760.14       Type B        57.25         176.95 
                                                                                      W    Type A          27.00         981.00 

 

This is an example of Table1 from which I want to return a result if a match is found using:

 

EarnCodeCategoryJoined
001Category A001 Category A
005Category B005 Category B

 

This is an example of the Table2 from which I want to return a result if a match is found:

 

DeductCodeTypeJoined
WType AW Type A
 Type BType B
 Type CType C

 

This is the DesiredResult table:

 

CSV StringEarnCodeCategoryDeductCodeType
                      001 Category A    11.11    13.121     1,232.11       1,125.15     Type C      145.21       1,641.85 001Category A Type C
      005 Category B        150    2.62       311.24         760.14       Type B        57.25         176.95 005Category B Type B
                                                                                      W    Type A          27.00         981.00   WType A

 

The logic I have in mind to populate the columns in the DesiredResult table looks something like this:

 

EarnCode: IF [CSV String] contains a value in Table1[Joined], then return matching Table1[EarnCode]

 

Category: IF [CSV String] contains a value in Table1[Joined], then return matching Table1[Category]

 

DeductCode: IF [CSV String]contains a value in Table2[Joined], then return matching Table2[DeductCode]

 

Type: IF [CSV String] contains a value in Table2[Joined], then return matching Table2[Type]

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.