PowerPivot Calculated Fields Across Multi Tables + Relationship Creation

Mfrosty

New Member
Joined
May 23, 2012
Messages
15
Happy Holidays Mr.Excel Forums!

The only present I want from Santa this year is the answer to these two problems.. Lame jokes aside, let's begin..

I am creating a dashboard with PowerPivot that is being driven from our MySQL db. Due to issues with the odbc connection driver I decided to store the data locally into excel files and connect powerpivot to that.

My two queries produce the following table structure in PowerPivot:

Table1 -- No unique Columns/Fields
DateWeekMonthQuarterYearClientLine ItemLI IDLI TypeLI PayoutTierImpressionsClicksSpent
12/1/12481242012DogBonez5CPCClicks22,564,15226,45412,382.99
12/1/12481242012CatFishez6CPCClicks1315,56414,5489,549.98
12/2/12481242012DogBonez5CPCClicks21,489,11214,9548,464.57
12/2/12481242012CatFishez6CPCClicks1545,97217,3619,834.11

<tbody>
</tbody>


Table2 -- No unique Columns/Fields
Line ItemLI IDStart DateEnd DateBudgetPayoutPayout PercentFeeGoal
Bonez52/2/1212/3/12$600,000$1.50$5,0001,000,000
Fishez68/9/1212/31/12$400,000$1.12800,000
Bonez512/3/123/1/13$200,000$1.40300,000
Purple72/14/135/1/13$100,000.12$5,000150,000

<tbody>
</tbody>


Table3 -- Unique lookup table to create a relationship between 1 and 2
LI ID
5
6
7

<tbody>
</tbody>



So that's what they look like. Query 1 groups by day & query 2 groups by almost all the fields to capture when a change in a line item occurs (new date, new budget, etc.)

Onto my 1st question..

I tried to create several calculated fields and was being met with this lovely error at every corner:

Code:
Calculation error in measure 'Table1'[Events to Date]: The value for column 'LI Type' in table 'line_item_total' cannot be determined in the current context. Check that all columns referenced in the calculation expression exist, and that there are no circular dependencies. This can also occur when the formula for a measure refers directly to a column without performing any aggregation--such as sum, average, or count--on that column. The column does not have a single value; it has many values, one for each row of the table, and no row has been specified.

For example I was trying to create a calculated field that would show the "events to date":

Code:
=IF(Table1[LI Type]= "percent", sum(daily[Spent])*(1+Table2[Payout Percentage]),IF(Table1[LI Type]= "CPC", sum(Table1[Clicks]), if(Table1[LI Type]= "CPF", sum(Table1[Connections]))))

I was reading through misc. forums about creating a new calculated field for each calculation first and wrapping it in 'CALCULATE()', but I didn't have any luck with that either. What am I missing here?



Onto my 2nd question..

What additional relationships or tables do I need to add so that I can create a PivotTable that combines Tables 1 & 2?
Example:
ClientLI IDLI TypeLI PayoutTierBudgetPayoutPayoutPercentFeeGoalStartDateEndDateImpressionsClicksSpent
Dog5CPCClicks2200,0001.40300,00012/3/123/1/131,489,11214,9548,464.57

<tbody>
</tbody>

And ultimately be able to splice this data by the Table 1 date field so I can see the line item progress over time.

Some material I read that "may" have my answer hidden in it: User-Friendly Report Sorting With Slicers! « PowerPivotPro

Sorry for the long post, and thanks in advance for any help/insights!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Man...This is probably the fastest I've answered a post in my life...

Check out that your DIM table (the one with the Id's for LI) is missing the TYPE column to show if it's for percent or if there's a CPC/CPF for it so I've created that column and put on some values in it.
What I did was:
- Act as Santa for 2 minutes while wearing a xmas hat
- Created calculated tables on the fact table to show the corresponding %percent and fee

Here's the file: https://dl.dropbox.com/u/54063091/Case.xlsx

I'm missing the:

=IF(Table1[LI Type]= "percent", sum(daily[Spent])*(1+Table2[Payout Percentage]),IF(Table1[LI Type]= "CPC", sum(Table1[Clicks]), if(Table1[LI Type]= "CPF", sum(Table1[Connections]))))

as I think that you should create a new calculated column instead of a measure (easy way) so you can get a column of the aggregate that you're trying to come up with.

Let me know if this xmas present is good enough! There's still time as Santa's still wearing the hat :LOL:

Miguel
 
Upvote 0
Thank you so much! Let me read through these and see what you did, but I hope this is the solution I have been looking for! Thanks Santa!

Edit: Just read through your calculations and they look spot on!

So just to re-cap: I basically want to just go through and create new calculatedcolumns in table 1 to bring over the values from table 2 after I have created a relationship between the two using table 3? Thank you!
 
Last edited:
Upvote 0
Sorry still having an issue:

"Calculation error in column 'daily'[]: A table of multiple values was supplied where a single value was expected."


edit: Nevermind mystery solved. Was missing a relationship! Thanks Santa!
 
Last edited:
Upvote 0
I was missing the last part but now you made it crystal clear! Instead of me doing the final solution, why don't you try using the columns now that you have them available in 1 table. :)
Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime.

In the event that you encounter any problems just post it here.

Best!
Miguel
 
Upvote 0
Sorry still having an issue:

"Calculation error in column 'daily'[]: A table of multiple values was supplied where a single value was expected."


edit: Nevermind mystery solved. Was missing a relationship! Thanks Santa!

Awesome! glad it worked.

Happy holidays!
Miguel
 
Upvote 0
Santa don't go just yet!

One more question. I am getting a calculation error when I try to migrate budget over. Here is my formula:

=CALCULATE(VALUES(payout_table[Budget]),FILTER(RELATEDTABLE(payout_table), [Date]>=payout_table[Start Date]),FILTER(RELATEDTABLE(payout_table), [Date]<=payout_table[End Date]))

Error: Calculation error in column 'Table1'[]: A table of multiple values was supplied where a single value was expected.

I assume I need to filter by something else to find a specific budget amt unique to a LI id?
 
Upvote 0
So I switched the VALUES() function to SUM() and it seems to work. It does product duplicates, but I can work around that.
 
Upvote 0
Hey frosty!

I'm on my phone right now but it seems that you are right, there are duplicates and that's why it can't give you just 1 distinct value in return. Could you upload the workbook with the formula that you are trying and what you're trying to accomplish?

Not the file that I created but your actual model so we can work with all the dependents.

Best!
Miguel a.k.a. Santa
 
Upvote 0

Forum statistics

Threads
1,215,160
Messages
6,123,355
Members
449,097
Latest member
thnirmitha

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