Forum Discussion
Summarize table by column
- 3 years ago
So try this.
Right click create new query >> blank query
Go to 'Advanced Editor' for this query and select all and paste in the below.
Then follow these steps again for option 2. Pick the one that works best for you. I think option 2.
Option 1
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "i45WCjRUMDIwMlSAAkOlWJ1oJTBBlowRSMYAJmNKhgxu00yQZIxBMkZwPQbkSKE4Ao+UCYorUBxILalYAA==", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t] ), #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] <> "")), #"Extracted First Characters" = Table.TransformColumns( #"Filtered Rows", {{"Column1", each Text.Start(_, 7), type text}} ), #"Renamed Columns" = Table.RenameColumns(#"Extracted First Characters", {{"Column1", "Quarter"}}), #"1" = Table.AddColumn(#"Renamed Columns", "1", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"2" = Table.AddColumn(#"1", "2", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"3" = Table.AddColumn(#"2", "3", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"4" = Table.AddColumn(#"3", "4", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"5" = Table.AddColumn(#"4", "5", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"Grouped Rows" = Table.Group( #"5", {"Quarter"}, { {"1", each List.Sum([1]), type number}, {"2", each List.Sum([2]), type number}, {"3", each List.Sum([3]), type number}, {"4", each List.Sum([4]), type number}, {"5", each List.Sum([5]), type number} } ) in #"Grouped Rows"Option 2
let Source = Table.FromRows( Json.Document( Binary.Decompress( Binary.FromText( "i45WCjRUMDIwMlSAAkOlWJ1oJTBBlowRSMYAJmNKhgxu00yQZIxBMkZwPQbkSKE4Ao+UCYorUBxILalYAA==", BinaryEncoding.Base64 ), Compression.Deflate ) ), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t] ), #"Filtered Rows" = Table.SelectRows(Source, each ([Column1] <> "")), #"Extracted First Characters" = Table.TransformColumns( #"Filtered Rows", {{"Column1", each Text.Start(_, 7), type text}} ), #"Renamed Columns" = Table.RenameColumns(#"Extracted First Characters", {{"Column1", "Quarter"}}), #"1" = Table.AddColumn(#"Renamed Columns", "1", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"2" = Table.AddColumn(#"1", "2", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"3" = Table.AddColumn(#"2", "3", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"4" = Table.AddColumn(#"3", "4", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"5" = Table.AddColumn(#"4", "5", each Number.RandomBetween(0.5, 15.3), Decimal.Type), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"5", {"Quarter"}, "Attribute", "Value"), #"Grouped Rows" = Table.Group( #"Unpivoted Other Columns", {"Quarter", "Attribute"}, {{"v", each List.Sum([Value]), type number}} ) in #"Grouped Rows"I think this should give you a better understanding of what I was trying to explain.
I'm not sure if I fully understand, but I think if you right click on your 'Qtr Year Query' and select, 'Unpivot other columns' I think your data will be in a better format to work with.
Do that before the 'Group by' step.
Right niw I have 999+ rows where in the column Qtr Year Query, where I have just a few categories (Qtr 1 2019, Qtr 1 2020, Qtr 1 2021, etc...) what I want is ONLY HAVING ONE ROW for each quarter
Combine al the rows of the same quarter insted of having a lot of them
Example: This what I have
Quarter 1-30
Q1 2021 1
Q1 2021 1
Q1 2021 1
Q2 2020 5
Q2 2020 5
Q2 2020 1
Q2 2020 4
Q3 2022 10
Q3 2022 10
Q3 2022 5
Q3 2022 5
Q4 2020 1
Q4 2020 1
Q4 2020 1
Q4 2020 1
This is what I want
Q1 2021 3
Q2 2020 15
Q3 2022 30
Q4 2020 4
- KNP3 years ago
Super User
Based on my understanding, I still think you need to do the unpivot, then the group by, including both your Qtr and new Attribute column that is created by the unpivot. i.e. select both columns and then select group by.
- Anonymous3 years agoNot applicable
I am still having the same error, but I don't have any nulls
- KNP3 years ago
Super User
Can you please paste some sample data that includes all the columns that matter to you?
Change anything you need to if it is sensitive info.
I'll try and create the steps I'm talking about.