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.
Hello,
I am trying to refactor this function that I apply on 10 differents columns.
fnConcatenate = (tbl as table) => Table.AddColumn(tbl, "field_1_combined", each if [id]>[linenumber] then Text.Combine(Table.SelectRows(tbl, (sel)=> sel[key] = [key] and sel[id]>= [id])[#"field_1"]) else [#"field_1"]),
fnConcatenate = (tbl as table) => Table.AddColumn(tbl, "field_2_combined", each if [id]>[linenumber] then Text.Combine(Table.SelectRows(tbl, (sel)=> sel[key] = [key] and sel[id]>= [id])[#"field_2"]) else [#"field_2"]),
...
fnConcatenate = (tbl as table) => Table.AddColumn(tbl, "field_10_combined", each if [id]>[linenumber] then Text.Combine(Table.SelectRows(tbl, (sel)=> sel[key] = [key] and sel[id]>= [id])[#"field_10"]) else [#"field_10"]),
Is it possible to have something like this
fnConcatenate = (tbl as table, field as text) => Table.AddColumn(tbl, "field" + "_combined", each if [id]>[linenumber] then Text.Combine(Table.SelectRows(tbl, (sel)=> sel[key] = [key] and sel[id]>= [id])[#"field"]) else [#"field"]),
?
Thanks
Kind regards
Saam
Solved! Go to Solution.
try
fnConcatField = (tbl as table, field as text) => Table.AddColumn(tbl, field & "_combined", each
if [id]>[linenumber] then Text.Combine( Table.Column(Table.SelectRows(tbl, (sel)=> sel[key] = [key] and sel[id]>= [id]), field)) else Record.Field(_, field))
try something like this (I haven't tested it)
try
fnConcatField = (tbl as table, field as text) => Table.AddColumn(tbl, field & "_combined", each
if [id]>[linenumber] then Text.Combine( Table.Column(Table.SelectRows(tbl, (sel)=> sel[key] = [key] and sel[id]>= [id]), field)) else Record.Field(_, field))
try something like this (I haven't tested it)
Column names can be created dynamically
fnConcatenate = (tbl as table, field as text) => Table.AddColumn(tbl, field + "_combined",
but they cannot be referenced (easily) dynamically. Have you considered using Expression.Evaluate() for this?
I never used Expression.Evaluate()
I will look for this approach
Thanks
Kind regards,
Saam
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.