# aggregating data in two different PowerPivot tables in one Pivot Table



## jameddelaney (Jan 28, 2012)

I have two PowerPivot tables:
1)     *AgentTimeData*


Data source: mysql
Data description: There is a row in this table for each transition a representative makes. So as a representative transitions from the statuses “waiting for a call” to “talking” to “wrap up” to “waiting for a call” again, 4 entries in this table are created in this table
Columns
AgentUserName
Status
StartDateTime
DurationOfTimeInStatus
 
Calculated Columns
StartDayYYYMMDD
keyAgentTimeDataAdjustments: a concatenated sting of AgentUserName, Status & StartDayYYYYMMDD
 
 
 2)      *AgentTimeDataAdjustments*


Data source: linked excel table
Data Description: Sometimes the data that we get from the database isn’t 100% accurate. For example, a representative will forget to log out of their workstation at the end of the day and because the agent software doesn’t have a good auto log out feature or permit time in status adjustments to be made w/in the application we need this table to record those adjustments. For now all adjustments are negative  (will reduce the time in status)
Column
AgentUserName
Status
DateOfAdjustment
DurationOfAdjustment
 
Calculated Columns
DateOfAdjustmentYYYMMDD
keyAgentTimeData: a concatenated sting of AgentUserName, Status & DateOfAdjustmentYYYYMMDD
 
 

  I am using the key fields to join these two tables together. I’d like to create a PivotTable from this PowerPivot data that will show me a list of AgentUserNames down the left and Statuses across the top and a the DurationAdjusted where DurationAdjusted will sum up all of the respective rows from the AgentTimeData and subtract the respective rows from the AgentTimeDataAdjustment table.


  So far I have created a DAX measure that doesn’t accomplish this task. It looks like this:


  =sum(AgentTimeData[DurationOfTimeInStatus]) – sum(AgentTimeDataAdjsutments[DurationOfAdjustment])


Can someone please tell me what I am doing wrong?


----------



## powerpivotpro (Jan 28, 2012)

Can you specify what you mean when you say it's not working?  Are you getting an error?  Or incorrect results in the pivot?  And if incorrect results, please give us an idea of what the incorrect results are (and what a correct result would look like).


----------



## jameddelaney (Jan 31, 2012)

my conclusion is that it is a bad "join" meaning a many to one join. this spreadsheet illustrates my point:
https://skydrive.live.com/#!/view.aspx?cid=CA968D3A3282B922&resid=CA968D3A3282B922!493

on the "AgentTimeData" tab swap the "Sample data that creates a bad join into the "AgentTimeData" excel table and refresh the "PowerPivotAnalysis" tab. you will then see the error.

to fix this i was going change AgentTimeDataAdjustment[DateOfAdjustment] to AgentTimeDataAdjustment[DateTimeOfAdjustment] to make the join a one to one join.

unless someone else had some other thoughts...


----------



## powerpivotpro (Jan 31, 2012)

OK I have looked at the xlsx and I think what you need more than anything is a third table.  Maybe even a fourth.

Whenever you have two or more "fact" tables - tables contain measurements or sales or anything else you want to write measures against - you generally cannot do what you need to do unless you add separate "master filter" tables.

This happens to be illustrated in a recent blog post:

http://www.powerpivotpro.com/2012/01/data-of-different-grains-a-followup/

I think what you ultimately will need to do, after introducing one or more filter tables, is write measures against each of your two fact tables ("AgentTime" measures and "Adjustment" measures).  And then you can write new measures that add together measures from each fact table ([Agent Time] - [Adjusted Time]) to get the desired results.


----------

