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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MarkusEng1998
Resolver II
Resolver II

Use a parameter in a function to merge tables

I have two sets of tables I want to merge together: CountryCodeFromdRofus and S01-General, S02-Parking, S03...

 

I created a function to be able to repeat the merge tables:

      CountryCodeFromdRofus and S01-General,

      CountryCodeFromdRofus and S02-Parking,

      CountryCodeFromdRofus and S03...

         .... 20+ more merges

 

 

 

let
    Source = (subGrp) => let
        Source = CountryCodeFromdRofus,
        filterGrp = Table.SelectRows(Source, each Text.StartsWith([Group], subGrp)),
        replaceNull = Table.ReplaceValue(filterGrp,null,"",Replacer.ReplaceValue,{"Value"}),
        addName = Table.AddColumn(replaceNull, "Name", each [CTRY] & " - " & [Group] & " - " & [Code]),
        removeCode = Table.RemoveColumns(addName,{"Group"}),
        orderCol= Table.ReorderColumns(removeCode,{"Name", "CTRY", "Code", "Value", "Country"}),
        mergeImport = Table.NestedJoin(orderCol, {"Name"}, #"S01-General", {"Name"}, "S01-General", JoinKind.LeftOuter),
        expandImport = Table.ExpandTableColumn(mergeImport, "S01-General", {"NewValue"}, {"NewValue"}),
        removeOtherCol = Table.SelectColumns(expandImport,{"Name", "Item No", "NewValue"})
in
    removeOtherCol

in
    Source

 

 

 

I created a function parameter subGrp to filter the first table. The subGrp parameter is also the name of the second table.

I also want to use it to merge the two tables. When I replace the text values (e.g. "S01-General") with the parameter, I get the error cannot convert value "#S01-General" to Table.

 

 

 

mergeImport = Table.NestedJoin(orderCol, {"Name"}, subGrp, {"Name"}, SubGrp, JoinKind.LeftOuter),
        expandImport = Table.ExpandTableColumn(mergeImport, subGrp, {"NewValue"}, {"NewValue"}),

 

 

 

 

My ultimate goal is to list the Item No from the first table, and the New Value from the second table.

I tried #subGrp, "#" & subGrp and "#"" &subGrp & """ to no success.

 

Please advise.

Thank you.

Function with variable 2022-02-24_7-20-47.jpg

 

1 ACCEPTED SOLUTION
MarkusEng1998
Resolver II
Resolver II

My workaround was to append all the second tables, and then merge that with the first table.

View solution in original post

1 REPLY 1
MarkusEng1998
Resolver II
Resolver II

My workaround was to append all the second tables, and then merge that with the first table.

Helpful resources

Announcements
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