I'm pretty new to custom functions in Power Query. I've created this one. Its purpose is to add a custom column whose content AND name are based on the parameters it gets. I've saved it as fnCompactedExamples:
let
CompactedExamples = (BaseTable as table, ExamplesTable as table, ExampleNumber as text) =>
let
Source = BaseTable,
#"Add example column" = Table.AddColumn( Source, "sb" & ExampleNumber, each Table.Column( ExamplesTable, Campaign & "_b" & ExampleNumber & "_example")),
#"Extracted values" = Table.TransformColumns(#"Add example column", { "sb" & ExampleNumber, each Text.Combine(List.Distinct(List.Transform(_, Text.From)), "#(lf)"), type text} )
in
#"Extracted values"
in
CompactedExamples
This function gets called in the following query:
let
Source = #"raw entities table",
#"Group by cny ID and Cny" = Table.Group(Source, {"Company ID", "Company"}, {{"Data", each _, type table}}),
#"create sb1 column" = fnCompactedExamples(#"Group by cny ID and Cny", [Data], "1")
in
#"create sb1 column"
Here is what the table looks like on the "Group by cny ID and Cny" stage
But on the "create sb1 column" stage, I get an error: "Expression.Error: There is an unknown identifier. Did you use the [field] shorthand for a _[field] outside of an 'each' expression?"
I feel close to the end, and that my error is some tiny detail. I scoured the web for hints on my case, but couldn't find any. Can anybody tell me what it that detail?
Edit, per @Olly's request:
The second argument ExamplesTable , is indeed a table that bears columns I want to kinda concatenate without any duplicate:
My purpose is to build a table like this, but right now I use a very repetitive series of instructions :