Add cumulative counts to a pivot table in excel

1

I have data in excel that looks like this:

Shop   | Division    | Launch Year
-------+-------------+-------------
Shop 1 | Division 1  | 2005
Shop 2 | Division 1  | 2006
Shop A | Division 2  | 2005
Shop B | Division 2  | 2007
...

And so on. There are about 100 shops total across 4 divisions. I need to get a table showing how many stores are open at the end of each year, per division. With a pivot table, I can easily show how many new stores were opened during that year, but not how many total.

I know how to add running totals to a pivot table, but in my case that doesn't work, as I don't have numbers to add - I need to add running counts instead. How can get that done?

I'm looking for this end result:

Year | Division 1 | Division 2 | ...
-----+------------+------------+----
2005 | 1          | 1          |
2006 | 2          | 1          |
2007 | 2          | 2          |
...

Aleks G

Posted 2019-12-18T09:18:55.500

Reputation: 352

See https://superuser.com/a/1333998/910710

– Akina – 2019-12-18T09:33:59.227

@Akina Thanks - but as I said in my question, I don't have numbers to add - I don't need running totals, I need running counts. – Aleks G – 2019-12-18T09:46:00.037

@Akina Thanks, but it's still not what I am after. I need running counts per division. I also need to be able to quickly update the table when source data changes. Have a look at my desired result – Aleks G – 2019-12-18T10:05:43.100

Feel free to ignore the ... - the data shown is exactly what I want. I don't think pasting 1000 rows of data into the question will make it any easier to understand. – Aleks G – 2019-12-18T10:12:32.247

The first link fully solves your task. See screenshot - the pivot is created according to the method described by the link, without any changes or additions. The only addition - I have removed totals, that does not affect the result.

– Akina – 2019-12-18T10:23:33.257

Unfortunately, it doesn't. When I use that method, all I get is 0 values across the entire table. This is because it relies on summing numbers in the data column. I don't have any numbers, therefore the sum is equal to 0. I need a running total of values from the pivot itself, not from the source data. – Aleks G – 2019-12-18T10:25:06.880

I don't have any numbers, therefore the sum is equal to 0 ??? WTF? Counting numbers, counting words - the count is a number anycase! – Akina – 2019-12-18T10:26:29.673

A text field's value is 0 when converted to number. Hence the running total is always 0. If you don't believe me, just try it. – Aleks G – 2019-12-18T10:28:26.527

1You try to SUM values??? you must COUNT them!!! – Akina – 2019-12-18T10:32:11.833

Of course I count them - but running totals only apply to source data, not to the counts in the pivot table. Again, try your suggestion for yourself - and you'll see what I mean and why it doesn't work. – Aleks G – 2019-12-18T10:42:19.557

Answers

1

A running count is a running total of 1s.
If the data allows for it, just throw down an additional column full of 1s and use those in your pivot for a running total.

Mara

Posted 2019-12-18T09:18:55.500

Reputation: 111

1

If your table is relatively static (columns and rows don't really change much) then use those those column headers and row headers. In the body, use formulas like (in pseudo code):

=countifs('Launch Year',"<="&'row header', 'Division', 'column header')

If you use the proper anchoring, you can build the formula once, and copy and paste it through out the entire body.

gns100

Posted 2019-12-18T09:18:55.500

Reputation: 571

I'd need to check this. Column headers don't change, but row headers are subject to change - and more rows added. – Aleks G – 2019-12-19T13:16:19.030

1

You don't need a pivot table for this.

Create your table as shown in your desired output. Populate the data area with the following array formula, entered with Ctrl Shift Enter and then copied across and down:

=SUMPRODUCT(--IF($C$2:$C$5<=$E2,1,0),IF($B$2:$B$5=F$1,1,0))

enter image description here

Update cell references as needed, paying mind to anchoring.

Sumproduct function documentation from MS.

You're using IF statements two generate two identically-sized arrays of matching values (the -- turns TRUE to 1 and FALSE to 0), multiplying them against each other to find records that match both criteria, then summing the resultant list of 1's and 0's to get your total.

EDIT: To respond to your comment/question

The setup shown here so far is a small data and results table for proof of concept. To make this more fully extensible, you'll probably turn the input table into a named table. To do this, select any cell in the relevant range (example: B4 in the setup as shown) and press Ctrl + T, then confirm in the resultant modal window. That will both make it easier to write cell references and automatically update any cell references to those data ranges as data gets added.

enter image description here

You can also make the results table a Table, too, using the same method. This way, when you add a new year, all you have to do is enter the year in the next row underneath that table and all the formulas will automatically paste down:

enter image description here

enter image description here

Note that this automatic updating of the output table will not work for adding a new Division. The table will expand to accommodate it, but you will have to manually copy the SUMPRODUCT formula into the new field.

Good luck and enjoy!

Alex M

Posted 2019-12-18T09:18:55.500

Reputation: 718

Would this work in my case of about 1000 rows, all different Shop names, across 5 divisions? And what would be required when a new shop is added? – Aleks G – 2019-12-19T13:17:39.063

Yes, this method is fully extensible. Shop names aren't used. You need only add years in the 'Year' field in the output table, and Division columns in the output table for each possible division in the data. I'll edit in some info to the rest of your questions. – Alex M – 2019-12-19T23:52:05.447