Forum Discussion
Is it possible to Ungruoup one column into 3 columns using get & transfrom
- 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
Joana, with this method you shall same name for the tables in all files you combine (or same name for sheets if you combine by sheets).
When you combine files you have the prompt "Select the object to be extracted from each file", take it literally.
Script takes the table, let say "MyTable", from each file in the list and combines them. Or "MySheet" if you combine by sheets. No other tables/sheets. If it doesn't find such you have an error.
You shall use same names or another logic to combine.
Thank you so much Sergei, that was exactly the issue. I didn't know it was important to have the same name on every table! Fantastic!!! I dont know how to thank you for so much help!
- SergeiBaklanNov 13, 2017Diamond Contributor
Something like attached
- SergeiBaklanNov 13, 2017Diamond Contributor
Hi Joana,
Raw idea is to create separate query with subtotals, merge it with main one before sorting (generating proper columns to merge), sort after that.
I could play with that in couple of days, on business trip now.
Regards,
Sergei
- Joana Villas-BoasNov 12, 2017Iron Contributor
Hi Sergei,
My model is almos finished. You helped me a lot with creating a list in the format I needed. After that I used Get&Transform to append the total number of rows 4 times, so each item could be attributed to 1,2, 3 or 4 suppliers. So I added a column to the result of our query that says supplier with a Data Validation that gets a list from all suppliers. (I know that's not a very good Idea because if the query gets refreshed the nr of rows can change and the suppliers can get all mixed up)
The only manual work the user has to do is to select the suppliers for each item and then a Macro creates one sheet by supplier that will be protected and sent to each supplier for them to fill prices and quantities. It's working great.
Now my client ask me if it is possible to have a subtotal row in our query bellow each item that repeats 4 times. 3.1.1 for exemple will apear 4 times in our result query and they want a subtotal before that. If we use group on the query editor we will loose the detail refight? I only know how to do sub-totals in the result pivot table, but not the query.
Thank you in advance for your help and patience with all my questions.
Regards, Joana