Forum Discussion
Table.Profile sum based on another column
- 6 years ago
Hi zaza ,
please try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyBGEDAwOlWJ1oCAdFALcSfPIGBpiGQMTQ1eBQYICwJRYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}), Custom1 = Table.Profile(#"Changed Type"), #"Added Custom" = Table.AddColumn(Custom1, "Custom", each List.Sum(Table.SelectRows(#"Changed Type", (inner) => Record.Field(inner, [Column]) = 1)[Column1])) in #"Added Custom"
I apologise for the confusion, I made a mistake in my original post and the follow up post as well and ended up asking for something totally different. I modified my original query instead of posting a new one. I hope now it's prefectly clear.
Hi zaza ,
I have no clue how to end up with 42 or 32 based on the sample data in the image you've given.
Please create an Excel-Workbook with sample data before and after, upload it to a clouds storage and paste the link to it here.
- zaza6 years agoResolver III
Here is the excel with the formulas, I think this will clear it up.
https://drive.google.com/file/d/1f2WhD5CVaamnnYzvs2AKMFZiAW0PBnqR/view?usp=sharing
- ImkeF6 years agoCommunity Champion
Hi zaza ,
please try this:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyBGEDAwOlWJ1oCAdFALcSfPIGBpiGQMTQ1eBQYICwJRYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}), Custom1 = Table.Profile(#"Changed Type"), #"Added Custom" = Table.AddColumn(Custom1, "Custom", each List.Sum(Table.SelectRows(#"Changed Type", (inner) => Record.Field(inner, [Column]) = 1)[Column1])) in #"Added Custom" - Anonymous6 years agoNot applicable
if you don't have other specific reasons to use table.profile, you can do the job without in this way, for exmple:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEyBGEDAwOlWJ1oCAdFALcSfPIGBpiGQMTQ1eBQYICwJRYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}), #"Demoted Headers" = Table.DemoteHeaders(#"Changed Type"), #"Changed Type1" = Table.TransformColumnTypes(#"Demoted Headers",{{"Column1", type any}, {"Column2", type any}, {"Column3", type any}}), #"Transposed Table" = Table.Transpose(#"Changed Type1"), #"Added Custom" = Table.AddColumn(#"Transposed Table", "SumCol11whereEq1", each List.Accumulate(List.PositionOf(Record.FieldValues(_),1,Occurrence.All),0,(s,c)=>s+Record.FieldValues(#"Transposed Table"{0}){c})) in #"Added Custom"