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

Custom Column to Return Value Comparing List with Corresponding List

Hello everyone!

 

Good morning! I'm trying to add a custom column [Customer Column_Output] to check through a list of text ([Commodity Description_List]) with a corresponding list (#"Type"[Description]) and return the value that is part of the #"Type"[Type]

 

Type

DescriptionType
40gp40ft
53hq53ft

 

Main Table

Commodity Description_ListCustom Column_Output
{40gp abc, def, ghi}{40ft, null, null, null}
{a 53hq, 40gp dh, abc}{53ft, 40ft, null, null}


I definitely will appreciate any help and thank you for your time!

6 REPLIES 6
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    List1 = {"40gp abc", "def", "ghi"},
    List2 = {"a 53hq", "40gp dh", "abc"},
    Source = Table.FromRecords({
    [Commodity Description_List= List1],
    [Commodity Description_List= List2]
}),
    #"Added Custom" = Table.AddColumn(Source, "Custom", (m)=> List.Generate(()=>[x=m[Commodity Description_List]{0},i=0], each [i]<List.Count(m[Commodity Description_List]), each [i=[i]+1, x=m[Commodity Description_List]{i}], each try Type[Type]{List.PositionOf(List.Transform(Type[Description],(r)=>Text.Contains([x],r)),true)} otherwise null))
in
    #"Added Custom"

 

Anonymous
Not applicable

Hi Vijay, thank you for that quick response. I statred a new query and pasted in the code and the error message was;

 

Expression.Error: The name 'Type' wasn't recognized. Make sure it's spelled correctly.

Test code for Type table (Hence, your query should be named Type)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjFIL1DSAVJpJUqxOtFKpsYZhUC+qTGIHwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Description = _t, Type = _t])
in
    Source
Anonymous
Not applicable

Hi Vijay! I found out the issue and it was because I did not have the table "Type"[Description] and "Type"[Type]. Now I do not have any error message but the custom column created now shows Function with each row showing "function (m as any) as any

 

I have included a screenshot for easy reference and thank you very much for your help again!

 

Power Query - PowerBI Forum.JPG 

Please post your complete query.

Anonymous
Not applicable

Hi Vijay, here you go

 

let
List1 = {"40gp abc", "def", "ghi"},
List2 = {"a 53hq", "40gp dh", "abc"},
Source = Table.FromRecords({
[Commodity Description_List= List1],
[Commodity Description_List= List2]
}),

#"Added Custom" = Table.AddColumn(Source, "Type", each (m)=> List.Generate(()=>[x=m[Commodity Description_List]{0},i=0], each [i]<List.Count(m[Commodity Description_List]), each [i=[i]+1, x=m[Commodity Description_List]{i}], each try #"Type"[Type]{List.PositionOf(List.Transform(#"Type"[Description],(r)=>Text.Contains([x],r)),true)} otherwise null))
in
#"Added Custom"

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.

Top Solution Authors
Top Kudoed Authors