Forum Discussion
carsoncheng
1 year agoRegular Visitor
Summary under subtotal
Hi, (Sorry if I post this to the wrong forum but I couldn't find a proper one.) I have these columns in my (simplified) data table in Excel: Faculty Year Program code Quota A 1 B0...
- 1 year ago
Hi carsoncheng, it is not ideal but possible also in PowerQuery:
Output
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYicDIAAxDA2UYnXQxI2ADCOEuBFM3BjEMYWLg7i+MHOMIeqdMMw3hYsboZsfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Faculty = _t, Year = _t, #"Program code" = _t, Quota = _t]), ChangedType = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Quota", type number}}), GroupedRows = Table.Group(ChangedType, {"Faculty"}, {{"T", each [ A = _, // A = GroupedRows{[Faculty="A"]}[T], SelectedCols = Table.Buffer(Table.SelectColumns(A,{"Year", "Quota"})), Ad_Totals = List.Accumulate(let lst = List.Distinct(SelectedCols[Year]) in lst & {lst} , A, (s,c)=> if c is number then Table.InsertRows(s, Table.RowCount(s), { SelectedCols{0} & [Faculty=if c = SelectedCols{0}[Year] then "By-year" else null, Year=c, Program code=null, Quota=List.Sum(Table.SelectRows(SelectedCols, each [Year] = c)[Quota])] }) else Table.InsertRows(s, Table.RowCount(s), { SelectedCols{0} & [Faculty=null, Year="Total", Program code=null, Quota=List.Sum(Table.SelectRows(SelectedCols, each List.Contains(c, [Year]))[Quota])] })), Ad_SpaceRow = Table.InsertRows(Ad_Totals, Table.RowCount(Ad_Totals), { List.Accumulate(Table.ColumnNames(Ad_Totals), [], (s,c)=> Record.AddField(s, c, null)) } ) ][Ad_SpaceRow], type table}}), CombinedT = Table.Combine(GroupedRows[T]), SelectedCols2 = Table.Buffer(Table.SelectRows(CombinedT, each [Program code] = null and [Year] <> null)[[Year], [Quota]]), Ad_Total = List.Accumulate(List.RemoveNulls(List.Distinct(SelectedCols2[Year])), CombinedT, (s,c)=> Table.InsertRows(s, Table.RowCount(s), { SelectedCols2{0} & [Faculty=if c = SelectedCols2{0}[Year] then "All" else null, Year=c, Program code=null, Quota=List.Sum(Table.SelectRows(SelectedCols2, each [Year] = c)[Quota])] })) in Ad_Total
Anonymous
1 year agoNot applicable
Hi carsoncheng ,
Thank you for connecting us on Microsoft Fabric Community Forum!
Thank you for the prompt response Poojara_D12 and Akash_Varuna , it helps to address the query.
I wanted to check and see if you had a chance to review our previous message or Please let us know if everything is sorted or if you need any further assistance.If our response addressed your query, please mark it as Accept as Solution and click Yes if you found it helpful.
Regards,
Pallavi.
- carsoncheng1 year agoRegular Visitor
Sorry, Pallavi, I don't see your previous message. And I haven't got a solution yet.