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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
0011AP
New Member

Adding new column with data from null row

I have data that list the name of the department in a row that is all null but for that one cell. I need to take the department name and make a new column with it list next to the dates. I have more then one row that has a different department name that needs to do the same. 

How do I take the department name CNK and add it a new column next to the date. and repeat that when an different department data shows  lower on the list ?

0011AP_1-1718147407955.png

 

 

5 REPLIES 5
dufoq3
Super User
Super User

Hi @0011AP, another solution:

 

Result

dufoq3_0-1718176756008.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("lY5JCoAwDEWvIlmXDrHjUrsUvEDp/a9hE1cFlQghP8PL0BpsSz0PUDBZVw2CcQYtriO32t6SwhDnyAWNlCAyHP/A+9vJeYtnyTSP5CLHo0tokqNZjlbZZ4Gl0DhVXOIY/cNnn2iWo0WI9gs=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"NS Hrs" = _t, #"NS Hrs target" = _t, #"Open Hrs" = _t, #"Selling Hrs" = _t, #"Selling Hrs target" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Date", type text}, {"NS Hrs", type number}, {"NS Hrs target", type number}, {"Open Hrs", Int64.Type}, {"Selling Hrs", type number}, {"Selling Hrs target", Int64.Type}}, "en-US"),
    Ad_DepartmentName = Table.AddColumn(ChangedType, "Department Name", each 
        [ a = Record.ToList(Record.RemoveFields(_, "Date")),
          b = if List.NonNullCount(a) = 0 then [Date] else null
        ][b], type text),
    FilledDown = Table.FillDown(Ad_DepartmentName,{"Department Name"})
in
    FilledDown

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

When I tried this is show as Table and not the department vaule, do you knwo I can convert this?

0011AP_0-1718227897750.png

 

I do not see your data. Could you paste whole query here?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

wdx223_Daniel
Community Champion
Community Champion

NewStep=Table.SelectColumns(Table.FromPartitions("Department",Table.ToRows(Table.Group(YourData,"Date",{"n",each Table.Skip(_)},0,(x,y)=>Byte.From(y is text)))),List.InsertRange(Table.ColumnNames(YourData),1,{"Department"})

Anonymous
Not applicable

Hi @0011AP ,

Please try this way.
Put all of this M function into the Advanced Editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclRw9vNW0lFCQbE60Uqm+ob6RgZGxkC+gZ4BhDI3BVKGhiDCVM8IxDEyAit2wmWKGYopJmDKAqTfCESYgdlA2dhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"NS Hrs" = _t, #"NS Hrs target" = _t, #"Open Hrs" = _t, #"Selling Hrs" = _t, #"Selling Hrs target" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"NS Hrs", type number}, {"NS Hrs target", type number}, {"Open Hrs", Int64.Type}, {"Selling Hrs", type number}, {"Selling Hrs target", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 1, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each let 
    currentIndex = [Index],
    prevIndex = currentIndex - 1,
    prevDate = Table.SelectRows(#"Added Index", each [Index] = prevIndex){0}[Date],
    output = if Text.EndsWith([Date], "CNK") then "delete" else prevDate
    in 
    output),
        #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Custom] <> "delete"),
        #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"Date", "Custom", "NS Hrs", "NS Hrs target", "Open Hrs", "Selling Hrs", "Selling Hrs target", "Index"}),
        #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Index"})
in
    #"Removed Columns"

And the final output is as below:

vjunyantmsft_0-1718155187437.png

I'm assuming that all of your department names end in CNK, but if they don't, please change the format that identifies all of them.

output = if Text.EndsWith([Date], "CNK") then "delete" else prevDate



Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.