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
joooffice
Helper I
Helper I

Copying value to another row based on another column

Hi

 

I'm trying to find a way to copy the contents of the Outstanding column to any other row that has the same ID number. The ID's are not necessarily sequential or (and i dont want to change the order) so i can't use row above/below

My data looks like:

IDNameOutstanding?
123Joe 
123SamFee Due
208Helen 
156BobFee Due
123Fred 
156Mike 
189CarolFee Due
156Anne 
208Lucy 
208Tony 

 

And i want the result to be:

IDNameOutstanding?
123JoeFee Due
123SamFee Due
208Helen 
156BobFee Due
123FredFee Due
156MikeFee Due
189CarolFee Due
156AnneFee Due
208Lucy 
208Tony 
1 ACCEPTED SOLUTION
ziying35
Impactful Individual
Impactful Individual

Hi, @joooffice 

let
    Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("i65W8nRRsjI0MtZR8kvMTVWyUvLKT1XSUfIvLSkuScxLycxLt1eyyivNyanVwVQbnJiLoVbJLTVVwaU0VQmmwcjAAq7BIzUnNQ+/8aZmcNVO+UmEjUd2j1tRagrRpvtmZhPwqYUlXLFzYlF+DhGOQTLfMS8Pv/nIAeNTmlxJtOKQ/DwcimMB",BinaryEncoding.Base64),Compression.Deflate))),
    fx = (tbl, id)=> Table.SelectRows(tbl, (r)=> (r[ID] = id) and (r[#"Outstanding?"] <> null)){0}?[#"Outstanding?"],
    result = Table.ReplaceValue(Source, each fx(Source, [ID]), each [#"Outstanding?"]=null, (x,y,z)=>if z then y else x, {"Outstanding?"})
in
    result

If my code solves your problem, mark it as a solution

ziying

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @joooffice 

 

You can try below solution:

let
    //Reference To my source Table
    Source = Table,

    // Dictionary for Outstanding Cases
    #"Removed Columns" = Table.RemoveColumns(Source,{"Name"}),
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns", each ([#"Outstanding?"] = "Fee Due")),
    OutstandingDict = Table.Distinct(#"Filtered Rows"),

    //Remove Outstanding? Column from Source
    #"Removed Column1" = Table.RemoveColumns(Source,{"Outstanding?"}),
    //Combine With Dictionary
    #"Merged Queries" = Table.NestedJoin(#"Removed Column1", {"ID"}, OutstandingDict, {"ID"}, "OutstandingDict", JoinKind.LeftOuter),
    //Get New Oustanding Column
    #"Expanded OutstandingDict" = Table.ExpandTableColumn(#"Merged Queries", "OutstandingDict", {"Outstanding?"}, {"Outstanding?"})

in
    #"Expanded OutstandingDict"
ziying35
Impactful Individual
Impactful Individual

Hi, @joooffice 

let
    Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("i65W8nRRsjI0MtZR8kvMTVWyUvLKT1XSUfIvLSkuScxLycxLt1eyyivNyanVwVQbnJiLoVbJLTVVwaU0VQmmwcjAAq7BIzUnNQ+/8aZmcNVO+UmEjUd2j1tRagrRpvtmZhPwqYUlXLFzYlF+DhGOQTLfMS8Pv/nIAeNTmlxJtOKQ/DwcimMB",BinaryEncoding.Base64),Compression.Deflate))),
    fx = (tbl, id)=> Table.SelectRows(tbl, (r)=> (r[ID] = id) and (r[#"Outstanding?"] <> null)){0}?[#"Outstanding?"],
    result = Table.ReplaceValue(Source, each fx(Source, [ID]), each [#"Outstanding?"]=null, (x,y,z)=>if z then y else x, {"Outstanding?"})
in
    result

If my code solves your problem, mark it as a solution

ziying

Mariusz
Community Champion
Community Champion

Hi @joooffice 

 

Sure on the attached, you will find a solution, just follow the query steps.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

 

Thanks Marius, I cant open the attchement though

 

Joanne 

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