Consolidate values in multiple columns for Pivot Table

queasyfish

New Member
Joined
Jun 15, 2006
Messages
4
Hello, any help would be appreciated.

I have a data set that includes day of week (7 choices) location (3 choices), start time and stop time (rounded to hour - 24 choices each). I have used formulas to fill in new columns showing specifically which hours are included between the start and stop time (lets call it "active" time).

For example, a row may contain: Monday/LocationA/10AM/2PM (then the formula filled in columns would contain:) 10/11/12/13/14 (military time).

I am wanting to use this data in a pivot table to be able to show on a graph; by day of week, by location, totals of "active time". So when I look at the graph for Monday(s) at 11AM I can see that there are 426 instances of active time for last month - or whatever.

So essentially I'm stuck because each row of data has more than one value for the "active time" field that would be on the pivot. In other words I want the pivot to show a data point for: "Monday/LocationA/10" and "Monday/LocationA/11" and Monday/LocationA/12" etc... My data set has about 30,000 rows.

I currently can pivot this data by start time only without a problem, but the multiple values per row has me stumped. Thanks in advance. John
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
...it doesn't have to be a pivot table, if fact it's sort of a one time calculation... a pivot seemed to be the most automated way - really that's what I want; a more automated way to get this data. Thanks again.
 
Upvote 0
Hi queasyfish,

You posed an interesting question. Especially with 30,000 records. It would be an overload for array formulae, I think.

Here is a solution utilising a query table. I gave the first data range, including headers, defined name "MD". And created another range "Times" with values 1 to 24.

Then via menu Data, Import External Data, New Database Query, Excel files, selected the file and then some fields from MD and the Times field. OK to the message about the wizard can't continue. When reaching MS Query hit the SQL icon and edit the SQL to become similar to
Code:
TRANSFORM
COUNT(*)
SELECT MD.day, MD.location
FROM `your file`.MD MD, `your file`.TL TL
WHERE MD.start <= TL.Times AND MD.stop >= TL.Times
GROUP BY MD.day, MD.location
PIVOT TL.Times

Enter that and then hit the "door" icon on the LHS of the SQL button to return the result to Excel. (If it hangs up, I find a quick CTRL-ALT-DELETE is enough to "wake it up".)

HTH
Fazza
 
Upvote 0
Thanks Fazza, I really appreciate your help;

I'm stuck at the SQL and have a few questions:

Overall it looks like you are trying to pull in and work with the "Times" range as one unit but SQL is erroring out.

1. In the From statement it does not recognize the ".TL TL" range but will accept ".Times Times".
2. (but then) I cannot find the right language in the Where statement to make it use the whole range of columns, it gives me a "not valid field" error on ".TL TL", "Times.TL", "TL.Times", "Times.Times" or "Times.*".
3. If I use "Times.F1" (one of the named columns in the Times range) it accepts it but this will not be the right data.
4. Even when I can get it to pull the range (table) and recognize the "Times.F1" field, I still get an error message saying that the "SQL query can't be represented graphically. Continue anyway?" - I just OK it. - this shouldn't be a showstopper should it?

Additional thought: The formula seems to be comparing the start and stop times with greater than/less than, but these time fields cross the midnight hour frequently and the numbers go from 23 to 0.

Thanks again for any time you can spend on this.
John
 
Upvote 0
Hi John,

Apologies, my description was inadequate for you earlier. I did not describe that the table I called "TL" had a header field "Times". When, the SQL refers to TL.Times it is referring to field Times in table TL.

I numbered my hours from 1 to 24. This could equally be 0 to 23. To be more specific, on a new worksheet, cell A1 entry "Times" and below that in successive cells from A2 to A25 numbers 1, 2, 3, 4, 5, etc through to 24. This whole range - header and data - I called TL.

If your data goes beyond midnight this creates a totally new challenge that I did not foresee in the original definition. How then will you know how many days there are? Even in your sample data, what if there is a start of 10am and an end of 2pm? It could be 4 hours later, 28 hours, 52 hours, etc, etc. I think it is important that you reconsider your whole data arrangement or provide a specification of how to interpret the times.

Your points 1 to 3 should now be fixed if your range is as I just described. Your point 4, yes click OK. Apologies again, I hope it is OK this time. Regards, Fazza
 
Upvote 0
Thanks Fazza;

...off to a busy start this week. I will try this and check those articles and reply later in the week.

Thanks!
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,376
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top