Forum Discussion

SumairChughtai's avatar
SumairChughtai
Copper Contributor
Jul 26, 2021
Solved

Creating a Table from Roll ups in Power Query

Hi,   Request the forum's input in transforming data from a roll up in a single column to a table in Power Query.   I have attached the Sample.   Regards,
  • SergeiBaklan's avatar
    Jul 26, 2021

    SumairChughtai 

    If you actual data has same logic as in sample, that could be

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        SplitIt = Table.SplitColumn(
            Source,
            "Column1",
            Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)),
            {"Code", "Description"}
        ),
        AddGroup = Table.AddColumn(
            SplitIt,
            "Group",
            each if [Description] = null then [Code] else null
        ),
        #"Filled Down" = Table.FillDown(AddGroup,{"Group"}),
        #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Description] <> null)),
        #"Reordered Columns" = Table.ReorderColumns(
            #"Filtered Rows",
            {"Group", "Code", "Description"}
        )
    in
        #"Reordered Columns"

    Key point is to split first column from digit to non-digit, the rest is straightforward.

Resources