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.
Sadly, you have to click the 'Add Aggegation' and manually add every column you want to summarize.
You can do it in the 'Advanced Editor' in the code if that is quicker for you. Depends on what your copy/paste/replace skills are like.
This is what I got
- KNP3 years ago
Super User
As far as the error is concerned, I think your "Over 90 Q" is missing a 'type nullable number', that might be causing that error.
I'll reply to your other comment separately.
- KNP3 years ago
Super User
If that doesn't help, you may need to explicitly set the type of the columns in the LND_SPF_PDREPORT to make sure it is set to decimal.
- Anonymous3 years agoNot applicable
But that is to add another column I want to summarize, the example is in my latest post