Forum Discussion

Joana Villas-Boas's avatar
Joana Villas-Boas
Iron Contributor
Oct 06, 2017
Solved

Is it possible to Ungruoup one column into 3 columns using get & transfrom

I have a table with a buget for works in a house like the one bellow. There is one column used to all descriptions, incluinding grouping items like this:   Article Description        Value 1.     ...
  • SergeiBaklan's avatar
    Oct 07, 2017

    Hi Joana,

     

    Perhaps there is more clever solution, but i did that in straigforward way - split Article on levels and fill each level by it names. Steps are in attached file, generated code is

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        DuplicateArticle = Table.AddColumn(Source, "Artcl", each [Article]),
        NullValueToZero = Table.ReplaceValue(DuplicateArticle,null,0,Replacer.ReplaceValue,{"Value"}),
        SplitArticleOnLevels = Table.SplitColumn(NullValueToZero, "Article", Splitter.SplitTextByDelimiter(".", QuoteStyle.Csv), {"Article.1", "Article.2", "Article.3"}),
        EmptyToNull = Table.ReplaceValue(SplitArticleOnLevels,"",null,Replacer.ReplaceValue,{"Article.2", "Article.3"}),
        AddFirstLevel = Table.AddColumn(EmptyToNull, "Custom1", each if [Article.2] = null then [Description] else null),
        FilledItDown = Table.FillDown(AddFirstLevel,{"Custom1"}),
        AddSecondLevel = Table.AddColumn(FilledItDown, "Custom2", each if [Article.3] = null and [Article.2] <> null then [Description] else null),
        NotRequired = Table.AddColumn(AddSecondLevel, "Custom22", each if [Article.2] = null then "" else [Custom2]),
        FillSecond = Table.FillDown(NotRequired,{"Custom22"}),
        RemoveNotRequired = Table.RemoveColumns(FillSecond,{"Custom2"}),
        AddThirdLevel = Table.AddColumn(RemoveNotRequired, "Custom3", each if [Article.2] <> null and [Article.3] <> null then [Description] else ""),
        RenameColumns = Table.RenameColumns(AddThirdLevel,{{"Artcl", "Article"}, {"Custom1", "Group"}, {"Custom22", "sub-group"}}),
        RemoveTempColumns = Table.SelectColumns(RenameColumns,{"Value", "Article", "Group", "sub-group", "Custom3"}),
        RenameFinally = Table.RenameColumns(RemoveTempColumns,{{"Custom3", "description"}}),
        Reordered = Table.ReorderColumns(RenameFinally,{"Article", "Group", "sub-group", "description", "Value"}),
        ProperType = Table.TransformColumnTypes(Reordered,{{"Article", type text}, {"Group", type text}, {"sub-group", type text}, {"description", type text}, {"Value", type number}})
    in
        ProperType

     

Resources