Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
2 years ago
Solved

New Colum with Facility names

Hello, 

 

I have something in need help with. 

 

I have a table that shows the facility name on top, ant then list the items. then on the same table it shows the next facility name and list the items of that facility again, as shown in the picture

 

I like to have the facility name in each row, but don't know how to do it. 

 

Thank you in advance for any help iIcan get.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Syndicate_Admin 

    You can put the following code to advanced editor in power query

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("1ZDBasMwDIZfxeRcllhZ2XYsdDttoYexS+hBUZTWsDbBccry9pNSOm9ljFwHRkj25x/xlWXyhOTeXRiTRbLh2mHwjnqzWckcz3ZRJs9tMK9jxzKvKLgT/0oUw6FiLzdvSOSObAo8KPnt9wsehwYpDH4CHz8650ezxqCPRXvTNmbd9txPmSh3qOXUkFRFIAObQmrvpLfZRFXSVlq6wdMee66lb87srbJZZDWG6Ctxd6GWaW4jpQF1fZW4v7AWUriPsG7FfL3kUiIhj9QP0z6qRgP/QzbMkZ2fNcLfskXhQ6TmyYZZspXafgI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Facility name", each if [Column1] = "Facility" then [Column2] else null),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Lot Type", each if [Column1]="Lot Type" then [Column2] else null),
        #"Filled Down" = Table.FillDown(#"Added Custom1",{"Facility name"}),
        #"Filled Down1" = Table.FillDown(#"Filled Down",{"Lot Type"}),
        #"Filled Up" = Table.FillUp(#"Filled Down1",{"Lot Type"}),
        #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([Column1] <> "Facility" and [Column1] <> "Lot Type")),
        #"Promoted Headers" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
        #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{"Pediatrics PA", "Facility name"}, {"Active", "Status"}}),
        #"Filtered Rows1" = Table.SelectRows(#"Renamed Columns", each ([Lot Number] <> "Lot Number")),
        #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows1",{"Facility name", "Status", "Lot Number", "Vaccine Name", "Lot Type", "Manufacturer", "Expiry Date", "No.of Doses"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Expiry Date", type date}, {"No.of Doses", Int64.Type}})
    in
        #"Changed Type1"

    Output

    Best Regards!

    Yolo Zhu

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

     

2 Replies

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    NewStep=Table.SplitColumn(Table.FromPartitions("x",Table.Group(YourTable,"Column1",{"n",each {[Column2]{0}&","&[Column2]{1},Table.PromoteHeaders(Table.Skip(_,2))}},0,(x,y)=>Byte.From(y="Facility"))[n]),"x",each Text.Split(_,","),{"Facility","Lot Type"})

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Syndicate_Admin 

    You can put the following code to advanced editor in power query

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("1ZDBasMwDIZfxeRcllhZ2XYsdDttoYexS+hBUZTWsDbBccry9pNSOm9ljFwHRkj25x/xlWXyhOTeXRiTRbLh2mHwjnqzWckcz3ZRJs9tMK9jxzKvKLgT/0oUw6FiLzdvSOSObAo8KPnt9wsehwYpDH4CHz8650ezxqCPRXvTNmbd9txPmSh3qOXUkFRFIAObQmrvpLfZRFXSVlq6wdMee66lb87srbJZZDWG6Ctxd6GWaW4jpQF1fZW4v7AWUriPsG7FfL3kUiIhj9QP0z6qRgP/QzbMkZ2fNcLfskXhQ6TmyYZZspXafgI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Facility name", each if [Column1] = "Facility" then [Column2] else null),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Lot Type", each if [Column1]="Lot Type" then [Column2] else null),
        #"Filled Down" = Table.FillDown(#"Added Custom1",{"Facility name"}),
        #"Filled Down1" = Table.FillDown(#"Filled Down",{"Lot Type"}),
        #"Filled Up" = Table.FillUp(#"Filled Down1",{"Lot Type"}),
        #"Filtered Rows" = Table.SelectRows(#"Filled Up", each ([Column1] <> "Facility" and [Column1] <> "Lot Type")),
        #"Promoted Headers" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
        #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{"Pediatrics PA", "Facility name"}, {"Active", "Status"}}),
        #"Filtered Rows1" = Table.SelectRows(#"Renamed Columns", each ([Lot Number] <> "Lot Number")),
        #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows1",{"Facility name", "Status", "Lot Number", "Vaccine Name", "Lot Type", "Manufacturer", "Expiry Date", "No.of Doses"}),
        #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Expiry Date", type date}, {"No.of Doses", Int64.Type}})
    in
        #"Changed Type1"

    Output

    Best Regards!

    Yolo Zhu

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