简体   繁体   中英

Excel: max() of count() with column grouping in a pivot table

I have a pivot table fed from a MySQL view. Each returned row is basically an instantiation of "a person, with a role, at a venue, on a date". The each cell then shows count of person (lets call it person_id).

When you pivot this in excel, you get a nice table of the form:

        | Dates -->
--------------------------
Venue   |
   Role | -count of person-

This makes a lot of sense, and the end user likes this format BUT the requirement has changed to group the columns (date) into a week.

When you group them in the normal way, this count is then applied in columns as well. This is, of course, logical behaviour, but what I actually want is max() of the original count() .

So the question: Does anyone know how to have cells count() , but the grouping perform a max() ?

To illustrate this, imagine the columns for a week. Then imaging the max() grouped as a week, giving:

Old:

         | M | T | W | T | F | S | S ||
---------------------------------------   .... for several weeks
Venue X  |
   Role Y| 1 | 1 | 2 | 1 | 2 | 3 | 1 ||

New (grouped by week)

         | Week 1 |    ...
---------------------------
Venue X  |
   Role Y|    3   |    ...

I'm not on my pc, but the steps below should be broadly correct:

  1. You should be able to right click on the date field on pivot table and select group.
  2. Then highlight week, you may have to select year also.
  3. Lastly right click on the count data you already have and expand the summarise by, and select max.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM