Forum Discussion
Counter for one unique expression for every row
- 5 years ago
https://drive.google.com/file/d/1cBpewQpejSBMtK2Pvk-_-t9pH0ORh3Ue/view?usp=sharing
see the Pbix in the link. Outline of the solution:
- add an index column to the table;
- duplicate the table (table (2);
- filter table (2) on "Date";
- add an index on tabel(2) (starting at 1);
- merge table and table (2) on index;
- fill the index column down;
Good luck,
//JW
- 5 years ago
Here is one way to do it in the query editor. To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below. Note that the Rename and Trim steps were only needed as the data you pasted had leading/trailing spaces.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckksST20ADtU0lFCF1IwMjAy1DMw1jMwUYrViVZyzs8tSMyrxKNXISS1uCQZogysxTOvuKSoNDc1r0SjWBNdMULSkBTFRjDHgDjFONwCdolCMkQRWAPZnjcjw/NGNPY9kYqNiQqq/JKM1CJEWMUCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"voteOptionText " = _t, #" voteAnswer" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"voteOptionText ", type text}, {" voteAnswer", type text}}), #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"voteOptionText ", "voteOptionText"}, {" voteAnswer", "voteAnswer"}}), #"Trimmed Text" = Table.TransformColumns(#"Renamed Columns",{{"voteOptionText", Text.Trim, type text}, {"voteAnswer", Text.Trim, type text}}), #"Added Custom" = Table.AddColumn(#"Trimmed Text", "DateForFillDown", each if [voteOptionText] = "Date" then [voteAnswer] else null, type text), #"Filled Down" = Table.FillDown(#"Added Custom",{"DateForFillDown"}), #"Grouped Rows" = Table.Group(#"Filled Down", {"DateForFillDown"}, {{"AllRows", each _, type table [voteOptionText=text, voteAnswer=text, DateForFillDown=text]}}), #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type), #"Expanded AllRows" = Table.ExpandTableColumn(#"Added Index", "AllRows", {"voteOptionText", "voteAnswer"}, {"voteOptionText", "voteAnswer"}), #"Removed Columns" = Table.RemoveColumns(#"Expanded AllRows",{"DateForFillDown"}) in #"Removed Columns"Pat
https://drive.google.com/file/d/1cBpewQpejSBMtK2Pvk-_-t9pH0ORh3Ue/view?usp=sharing
see the Pbix in the link. Outline of the solution:
- add an index column to the table;
- duplicate the table (table (2);
- filter table (2) on "Date";
- add an index on tabel(2) (starting at 1);
- merge table and table (2) on index;
- fill the index column down;
Good luck,
//JW
Thank you very much for your help!
Unfortunately I'm not able to open your file, but I tried to do the steps you mentioned manually. But if I do that I get a table with numbers on each row with the expression "data". The rest of the rows gets filled with "null". It looks like that:
voteOptionText voteAnswer index index.1.index index.1.index.1
Date 2021.03.04 1 1 1
Company Testcompany 2 null null
Instrument(s) Instrument1 3 null null
Instrument(s) Instrument2 4 null null
Comments Test comment 5 null null
Date 2021.03.06 6 34 2
Company Testcompany2 7 null null
Instrument(s) Instrument1 8 null null
Instrument(s) Instrument2 9 null null
Instrument(s) Instrument3 10 null null
Comments other comment 11 null null
What did I wrong?