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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
marabeda
Helper I
Helper I

Modify table

Dear Community, I am new on Power BI and in particular in codig with m language. So be so kind to explain easily.

I have a table where in the column "Cliente/mandato" the names of the clients and of the sellers. The names of the seller are above the name of clients (picture1 in yellow is the name of the seller). I want to create a column where I associate the name of client to the seller on the same row, like in picture 2.

Thank you for your precious help.

Marabeda

Picture 1

immagine.png

 

Picture2

immagine.png

 

2 ACCEPTED SOLUTIONS
KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @marabeda ,

 

Please see below solution based on screenshot:

1. add a custom step and paste over the code below(a) (The screenshot below shows you where to add the custom step).

KT_Bsmart2gethe_0-1655041054389.png

 

(a) Code for custom step:

Table.FillDown(Table.AddColumn(#"Changed Type", "Custom", each if List.ContainsAny(Record.ToList(_), {null}) then List.First(Record.ToList(_)) else null), {"Custom"})

 

Translate:

1. Record.ToList(_) converts each row into a list.

2. List.ContainsAny(Record.ToList(_), {null}) search through the list at each row for null

3. if the row contains null then List.First(Record.ToList(_)) i.e. get the first value from the list  else null

4. Table.AddColumn() Add a new column

5. Table.FillDown() Fill down the value in the newly added column

 

Regards

KT

View solution in original post

v-kkf-msft
Community Support
Community Support

Hi @marabeda ,

 

Please open a blank query and paste the code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc0xCsAgDAXQq0jmLmrVg7SbOEjJIKhDtfevSIdAhUCWHx7/ew8Nc8Zb1FhQSNjgu7B5uHLC2uf3wN5TiTVmHOl8RhJJFGxpREm14rSams6q5azmivSvSC+Ldq5op9pw2lBtOW2pdpx2EMIL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cliente/mandato" = _t, Cadenza = _t, Orario = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cliente/mandato", type text}, {"Cadenza", type text}, {"Orario", type text}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Is seller", each if List.Count(List.Select(Record.ToList(_), each  _ <> "" and _ <> null)) = 1 then [#"Cliente/mandato"] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Fill", each [Is seller]),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"Fill"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Is seller] = null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Is seller"})
in
    #"Removed Columns"

vkkfmsft_0-1655193754477.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-kkf-msft
Community Support
Community Support

Hi @marabeda ,

 

Please open a blank query and paste the code.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hc0xCsAgDAXQq0jmLmrVg7SbOEjJIKhDtfevSIdAhUCWHx7/ew8Nc8Zb1FhQSNjgu7B5uHLC2uf3wN5TiTVmHOl8RhJJFGxpREm14rSams6q5azmivSvSC+Ldq5op9pw2lBtOW2pdpx2EMIL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Cliente/mandato" = _t, Cadenza = _t, Orario = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Cliente/mandato", type text}, {"Cadenza", type text}, {"Orario", type text}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Is seller", each if List.Count(List.Select(Record.ToList(_), each  _ <> "" and _ <> null)) = 1 then [#"Cliente/mandato"] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Fill", each [Is seller]),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"Fill"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Is seller] = null)),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Is seller"})
in
    #"Removed Columns"

vkkfmsft_0-1655193754477.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @marabeda ,

 

Please see below solution based on screenshot:

1. add a custom step and paste over the code below(a) (The screenshot below shows you where to add the custom step).

KT_Bsmart2gethe_0-1655041054389.png

 

(a) Code for custom step:

Table.FillDown(Table.AddColumn(#"Changed Type", "Custom", each if List.ContainsAny(Record.ToList(_), {null}) then List.First(Record.ToList(_)) else null), {"Custom"})

 

Translate:

1. Record.ToList(_) converts each row into a list.

2. List.ContainsAny(Record.ToList(_), {null}) search through the list at each row for null

3. if the row contains null then List.First(Record.ToList(_)) i.e. get the first value from the list  else null

4. Table.AddColumn() Add a new column

5. Table.FillDown() Fill down the value in the newly added column

 

Regards

KT

AlB
Community Champion
Community Champion

Hi @marabeda 

Can you share some sample data in text-tabular format, so that the data can be copied?

Then we can build a solution upon that

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors