Forum Discussion
Vimal_Gaur
Feb 21, 2023Brass Contributor
Column row-wise total based on Heading containing specific text
I have a sheet that contains several headings with amount below them in rows I need sum of columns having heading containing SGST / CGST / IGST in separate columns as mention in result tables.
Patrick2788
Feb 22, 2023Silver Contributor
A 365 solution to consider:
Dynamic range 'InputData' - this is all your data from column 3 to the end
=LET(n, Sheet1!$C$2:$M$10000, nonblank, COUNTA(TAKE(n, , 1)), TAKE(n, nonblank))
Dynamic range 'Names' - this is first two columns
=LET(n, Sheet1!$A$2:$B$10000, nonblank, COUNTA(TAKE(n, , 1)), TAKE(n, nonblank))
'Terms' - an array constant of terms for REDUCE to check
={"SGST"; "CGST"; "IGST"}
Lambda - 'Total' - this function filters each of the terms and stacks them horizontally. An additonal stack is created for the totals columns.
=LAMBDA(a,v,LET(
filtered, FILTER(InputData, TEXTBEFORE(TAKE(InputData, 1), " ") = v),
HSTACK(
a,
filtered,
BYROW(
filtered,
LAMBDA(row, IF(COUNT(row) = 0, TEXTBEFORE(TAKE(row, , 1), " ") & " Total", SUM(row)))
)
)
))
Sheet level formula:
=REDUCE(Names,Terms,Total)