cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Theiamania
Frequent Visitor

Row with an empty cell, find another row with the same name but with that cell and copy the value

I am using rows with two types of information: devices and the serial numbers of those devices, both have same name in first column. Here is an example:

Device nameDevice QRSerial QR
Device 100011 
Device 1 S0012
Device 1 S0013
Device 200022 
Device 2 S0023

 

I need to fill in the empty cells in the Device QR column. In each row I have a name. Now, for each empty cell in that column, I need to find the name of its row, use that name to find another row with the same name but with a value in the cell in the Device QR column and paste that value into the empty cell in the first row.

 

Device nameDevice QRSerial QR
Device 100011 
Device 100011S0012
Device 100011S0013
Device 200022 
Device 200022S0023

 

How can I do it?

3 REPLIES 3
ronrsnfld
Resident Rockstar
Resident Rockstar

In the Power Query editor, assuming the blank cells in DeviceQR are null, just select that column and "Fill Down".  If the blanks are null strings, then replace them with null first.

tackytechtom
Super User
Super User

Hi @Theiamania ,

 

How about this:

 

Before:

tackytechtom_0-1666371572585.png

 

After

tackytechtom_1-1666371592115.png

 

 

Here the code in M:

tackytechtom_2-1666371644949.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wckkty0xOVTBU0lEyMDAwBNEKSrE6KBIKQBwMlDTCJWGMLGEEMcrICN0oI4QOI6COWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Device name" = _t, #"Device QR" = _t, #"Serial QR" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Device name", type text}, {"Device QR", Int64.Type}, {"Serial QR", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Device QR] <> null)),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Device name"}, #"Filtered Rows", {"Device name"}, "Filtered Rows", JoinKind.LeftOuter),
    #"Removed Columns" = Table.RemoveColumns(#"Merged Queries",{"Device QR"}),
    #"Expanded Filtered Rows" = Table.ExpandTableColumn(#"Removed Columns", "Filtered Rows", {"Device QR"}, {"Filtered Rows.Device QR"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Filtered Rows",{{"Filtered Rows.Device QR", "Device QR"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Device name", "Device QR", "Serial QR"})
in
    #"Reordered Columns"

 

I'd suggest you use that code and have a look into the APPLIED STEPS on the right to see what I have done. Essentially, I filered only the rows that do not have NULLs in Device QR. I then joined that table with the original table. From there, it was just some cosmetics like dropping the original column, expanding the Device QR column from the merged table, renaming and finally some reordering.

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks @tackytechtom 

 

Your solution works but generates new rows that did not originally exist. These new rows appear to be all Devices but they don't have any other Serial rows with the same 'Device name'.

Sorry, I didn't think that point was relevant and didn't specify it above. I leave an example below of what the table originally looks like.

Device nameDevice QRSerial QR
Device 100011 
Device 1 S0012
Device 1 S0013
Device 200022 
Device 2 S0023
Device 300033 
Device 400044 
Device 4 S0045

 

This duplicity is created in the 'Expanded Filtered Rows' step. But, from what you say and as I didn't specify the above detail, I think it makes the whole process approach no longer valid. Is this the case?

 

I am very grateful for your time.

 

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors