Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pivot data dependent on diff data for each column? 1

Status
Not open for further replies.

dstein

IS-IT--Management
Jun 21, 2002
7
US
Well, this group of experts hasn't failed me yet, so here's another puzzler (at least to me). Apologies at the outset if I'm using the wrong terminology for certain things.

Background: I am tracking monthly telephone expenses for users. For any random month, the user belongs to a specific cost center. Since users can move between cost centers, the complete set of data for a particular user for a particular month includes their CC and the $amt they spent.

Spreadsheet layout (columns)

Last | First | CCinJan | $Jan | CCinFeb | $Feb | etc.

The CCinX field is a lookup that matches First and Last against another table (an HR headcount report) to derive the CC the user belonged to that month.

I have a series of pivot tables, one for each month, that I supply to the Finance dept showing the monthly allocation results. Their table basically looks like:

CC1inMonthX [pivot row=CCinJan]
Last1 [pivot row=Last] $amtinMonthX1 [pivot data=$Jan]
Last2 $amtinMonthX2
CC2inMonthX
Last3 $amtinMonthX3
...etc

As currently implemented, the spreadsheet does exactly what I want.

My challenge now is this: I wish to supply each CC Manager with a summary of his/her CC spending, and ONLY his/her CC. I can certainly do this with my existing pivots simply by selecting to display only the CC of choice. However, I would like to be able to provide the CC mgr with an annual view rather than just a monthly view. In other words,
I'd like to be able to present them with something like:

$Jan $Feb $Mar
Last1 amtInJan1 amtinFeb1 amtinMar1
Last2 amtInJan2 amtinFeb2 amtinMar2
...etc

The problem, you might note, is that the data extracted for (e.g.) amtInJan1 should only be extracted for this CC IF CCinJan=currentCC, and for amtInFeb2 only if CCinFeb=currentCC. Therefore, the initial stab of:

CCinJan [pivot row]
Last [pivot row]
amtInJan [pivot data]
amtinFeb [pivot data]
amtInMar [pivot data]

obviously fails. It certainly shows all billings for users in CC X in Jan, but the values returned for Feb (e.g.) are returned even if the employee was in a different CC in Feb, etc.

I'm trying to figure out how to have the data elements of my table be correctly selected and displayed in the appropriate columns. It seems to me this is more than can be handled by simple table layout (and I have this nagging feeling that this is still Pivot Table 101 stuff, but consider me still trapped in the Survey for Non-Majors course <g>)

Any ideas?
 
dstein,

1) You need to NORMALIZE your data to
[tt]
Last | First | CC | CC_Date

[/tt]
faq68-5287 NORMALIZE Your Table using the PivotTable Wizard.

2) Then its a SNAP to get the report you want with the Pivot Table LAYOUT...
[tt]
CC_Date
Last First |Sum of CC
[/tt]
CC_Date should be a REAL DATE and then you can GROUP CC_Date by Month & Year

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Man, I love this user community!

Skip - thanks for the reply. I'm trying to take the general lessons of your post/faq and fit it into my situation. My confusion right now is that my source data isn't quite in the simple format of

LAST JAN FEB MAR
last1 234 123 567
last2 345 234 678

but is more like

LAST JAN FEB MAR
last1 99 234 99 123 99 567
last2 98 345 90 234 90 678

My source data is actually more complex in that there are a lot of columns of values between things, but if those columns are ignored it does conceptually distill down to this.

I'm trying to figure out the mechanics of range selection at step 2b of the FAQ such that I end up with

ROW Column Value Value
last1 JAN 99 234
last1 FEB 99 123
last1 MAR 99 567
last2 JAN 98 345
last2 FEB 90 234
last2 MAR 90 678

My initial 15 minute foray to try to do this is running into various snags - from your experience, is the process you suggest using to normalize the data still valid for this multi-dimensional factoring, or am I doomed to failure?
 
First I'm glad to hear that you are willing to take the initial "HURT" to generate a table that will ultimately be able to accomplish what you want and probably even alot more.

This may take a number of sucessive transformations (for instance, one month's worth of data at a time.) After all, each row in your new table is...

one month's worth of data.

Post a few rows of your current table and I may have another suggestion or so.



Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
There's another possible approch, with MS Query using Data/Get Externl Data/New Database Query -- excel files -- YOUR WORKBOOK -- then SHEET containing your Table of data, [Next],[Next],[Next],[Next],Option Button to EDIT the Query, [Finish]

Now in the Query Grid enter the columns you want in the new table (last, First) and the DATA for ONE MONTH (CCinJan, $Jan)

Then hit the SQL button.

Now modify the sql thusly...
[tt]
Select 'Sheet1'.Last, 'Sheet1'.First, 'Sheet1'.CCinJan, 'Sheet1'.$Jan
From 'C:\whatever.xls'.'Sheet1' 'Sheet1'[/tt][tt]
UNION
Select 'Sheet1'.Last, 'Sheet1'.First, 'Sheet1'.CCin[red]Feb[/red], 'Sheet1'.$[red]Feb[/red]
From 'C:\whatever.xls'.'Sheet1' 'Sheet1'
UNION
Select 'Sheet1'.Last, 'Sheet1'.First, 'Sheet1'.CCin[red]Mar[/red], 'Sheet1'.$[red]Mar[/red]
From 'C:\whatever.xls'.'Sheet1' 'Sheet1'
...[/tt]


Then File/Return data to Excel.

:)

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Skip - while prepping this response I see you've offered another suggestion using MS Query. I haven't yet looked at your response to get my hands around it, but will do so in a few minutes.

Following is an extract of the first 3 rows and first 2 months of my current sheet. Extend out another 10 months and you can visualize the whole thing. Sorry the alignment is so messed up - it appears that using TGML color tags resets the TGML tt tag. As soon as I invoked color the monospace font disappeared. The colors are meant to show user data entry fields (lime background) vs calc/lookup fields (cyan).

The column labeled "xx" is a blank column that visual separates each monthly section. On the actual sheet the xx is white on white, but has to be there since I use auto-filters on this row and you can't have an empty column when trying to setup your filters. In the extract below, the data that seems to appear under the xx is actually the Plan# for Feb, so mentally push all the data over 1 column.

The key thing about this random extract is that Gerald Ford switches cost center (Dept) in Feb. Therefore, he's supposed to ultimately appear on reports for two different cost center managers - the CC25400 manager will see Ford's billings in Jan (only), while the CC2500 manager will see Ford's billings in Feb (and onward and probably March, etc.)

Last First Plan # Dept Audio Net SubTtl Overhead GrandTtl xx Plan # Dept Audio Net SubTtl Overhead GrandTtl
Adams John 1 33100 $167.97 $- $167.97 $(5.48) $162.49 1 33100 $126.14 $- $126.14 $(2.12) $124.02
Ford Gerald 1 25400 $169.63 $- $169.63 $(5.54) $164.09 1 25000 $77.81 $- $77.81 $(1.31) $76.50
 
First, every column must have a UNIQUE HEADING NAME. So, change the HeaderNames for the FIRST MONTH's COLUMNS as follows
[tt]
Plan#1 Dept1 Audio1 Net1 SubTtl1 Overhead1 GrandTtl1 xx1
[/tt]
Then SELECT those cells and DRAG ACROSS to the end of the data area.

Now you should have Dept1 to Dept12 and so on.

Here is my SQL for two months, using MS Query from my sheet named DATABASE...
Code:
SELECT `DATABASE$`.Last, `DATABASE$`.First, `DATABASE$`.`Plan#1`, `DATABASE$`.Dept1, `DATABASE$`.Audio1, `DATABASE$`.Net1,  `DATABASE$`.Overhead1, #1/1/2004#
FROM `C:\Documents and Settings\metzgerc\My Documents\vbaexcel\xldb3`.`DATABASE$` `DATABASE$`
union
SELECT `DATABASE$`.Last, `DATABASE$`.First, `DATABASE$`.`Plan#2`, `DATABASE$`.Dept2, `DATABASE$`.Audio2, `DATABASE$`.Net2,  `DATABASE$`.Overhead2, #2/1/2004#
FROM `C:\Documents and Settings\metzgerc\My Documents\vbaexcel\xldb3`.`DATABASE$`  `DATABASE$`
and here are the results
[tt]
Last First Plan#1 Dept1 Audio1 Net1 Overhead1 Expr1007
Adams John 1 33100 126.14 $- -2.12 2/1/04
Adams John 1 33100 167.97 $- -5.48 1/1/04
Ford Gerald 1 25000 77.81 $- -1.31 2/1/04
Ford Gerald 1 25400 169.63 $- -5.54 1/1/04
[/tt]
BTW, summary fields (subtotals,totals) are not generally STORED in a table. These are REPORTING elements, that you can generate very easily via a PivotTable.

:)


Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Skip - FANTASTIC! Works like a charm and then some. I've managed to create similar tables for my company's Conf Calling, Calling Card, and Cell Phone expenses (which are tracked in different tabs and each have slightly different layouts).

Now I'm going to mess around and see if I can come up with some kind of snazzy way to suck all 3 sets of data into one normalized table so I can send each CC manager a report that combines all 3 sets of data into one table rather than 3 different tables. Even if I can't get that going your tip is going to save me several hours of work each month.

Thanks!
 
Carefully plan your table redesign. Read, digest and understand the Fundamentals of Database Design. Post any other questions regarding your design in a new thread to get the best response.

Be careful about combining TOO much into one table (like Customers and Invoices). Remember, a Table is a Relationship. A Table with multiple reationships becomes a maintenance nightmare and inefficient. However, there are times that breaking the rules is desireable when PROCESSING becomes an issue.

Skip,

Want to get great answers to your Tek-Tips questions? Have a look at faq222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top