Thursday 8 December 2022

Sum totals for Columns redux


Back October I showed how to run a quick sum of a column in Power Query. But I curious to know how I could see this total alongside a count of the number of rows. It turns out this is quite easy because you can include text in your output from a Power Query script. In fact you can even combine these two totals with an explanation as I have done above.

A few points to remember in doing this:
1. If you're creating a variable* in Power Query (i.e. a line in the M code) you don't have to call it right away you can call on it in the final "in" line.

2. You can't minx numbers with text unless you convert them to text first.

So the only code you need really (on top of what you many have already done) is:

#"Counted Rows" = Table.RowCount(#"PreviousRow"),
Total = List.Sum(#"Filtered Rows1"[Users])

in

"Total= "&Text.From(Total)&" from "&Text.From(#"Counted Rows")&" rows"