This is basic. What am I doing wrong!!

tbone56

New Member
Joined
May 23, 2011
Messages
7
In Power Pivot I have imported 2 simple (excel) table (see below).
In each table I created (within Power Pivot) a calculated column "Link" to provide a unique key.

Theses links are used in a relationship

Price Table
The Link Column is a calculated field ie CONCATENATE(Product Code,Country)
[TABLE="width: 0"]
<tbody>[TR]
[TD]Product Code[/TD]
[TD]Price[/TD]
[TD]Discount[/TD]
[TD]Country[/TD]
[TD]Link[/TD]
[/TR]
[TR]
[TD]A1[/TD]
[TD]$10.34[/TD]
[TD]$9.31[/TD]
[TD]AU[/TD]
[TD]A1AU[/TD]
[/TR]
[TR]
[TD]A2[/TD]
[TD]$12.76[/TD]
[TD]$11.48[/TD]
[TD]AU[/TD]
[TD]A2AU[/TD]
[/TR]
[TR]
[TD]A3[/TD]
[TD]$18.79[/TD]
[TD]$16.91[/TD]
[TD]AU[/TD]
[TD]A3AU[/TD]
[/TR]
[TR]
[TD]B1[/TD]
[TD]$6.98[/TD]
[TD]$6.28[/TD]
[TD]AU[/TD]
[TD]B1AU[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[TD]$5.43[/TD]
[TD]$4.89[/TD]
[TD]AU[/TD]
[TD]B2AU[/TD]
[/TR]
[TR]
[TD]B3[/TD]
[TD]$8.34[/TD]
[TD]$7.51[/TD]
[TD]AU[/TD]
[TD]B3AU[/TD]
[/TR]
[TR]
[TD]B4[/TD]
[TD]$7.83[/TD]
[TD]$7.05[/TD]
[TD]AU[/TD]
[TD]B4AU[/TD]
[/TR]
[TR]
[TD]A1[/TD]
[TD]$11.06[/TD]
[TD]$9.96[/TD]
[TD]NZ[/TD]
[TD]A1NZ[/TD]
[/TR]
[TR]
[TD]A2[/TD]
[TD]$13.65[/TD]
[TD]$12.29[/TD]
[TD]NZ[/TD]
[TD]A2NZ[/TD]
[/TR]
[TR]
[TD]A3[/TD]
[TD]$20.11[/TD]
[TD]$18.09[/TD]
[TD]NZ[/TD]
[TD]A3NZ[/TD]
[/TR]
[TR]
[TD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A2[/TD]
[TD]31[/TD]
[TD]NZ[/TD]
[TD]A2NZ[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]B4[/TD]
[TD]7[/TD]
[TD]AU[/TD]
[TD]B4AU[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Next I created a relationship for the 2 “Link” columns. Sorry I cannot paste the screenshot

I now want to use the relationship. The Value column in the Sales table is a simple calculated field ie =[Qty]*Price[Price] which should produce the “Value” of the sale. But I get the following error in every row

"The value for column 'Price' in table 'Price' 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."


What am I doing wrong!:confused:
 
Try as follows:
In Sales_tbl add the CalculatedColumn with the following formula:=LOOKUPVALUE(Price_tbl[Cal_price],Price_tbl[Link],[Link]) rename it 'Linked_price'
Then add another Column 'Value' with the formula =[Qty]*[Linked_price]
Would that work for you?


Excel 2010
ABCDEF
1Product CodeQtyCountryLinkLinked_priceValue
2A225AUA2AU$ 12.76$ 319.00
3B118AUB1AU$ 6.98$ 125.64
4B167AUB1AU$ 6.98$ 467.66
5B147NZB1NZ$ 7.47$ 351.09
6B143NZB1NZ$ 7.47$ 321.21
7B457NZB4NZ$ 8.38$ 477.66
8B244AUB2AU$ 5.43$ 238.92
9A366NZA3NZ$ 20.11$ 1,327.26
10A231NZA2NZ$ 13.65$ 423.15
11B47AUB4AU$ 7.83$ 54.81
Sales
 
Upvote 0
When you create a calculated column it has a "row context". The calculation is done 1 row at a time, and can thus reference things like Price[Price].

For a measure (calculated field)... you are talking about things "in aggregate". Many rows at once. If you were writing a "Total Sales" measure, you would write =SUM(Price[Price]) and be happy. SUM() is used to aggregate multiple rows together.

Your measure has =[Qty] but look at B1NZ... you have 2 of them!

You probably have two choices here:
1) add a calc column for price*qty (as cyrilbrd suggests, though copying the price over isnt needed, you can just use RELATED())
2) write your measure something like =SUMX(Sales, Sales[Qty] * VALUES(MIN(Price[Price]))

SUMX is going to iterate 1 row at a time, so Sales[Qty] with no aggregate is fine. But the price table isn't really part of that row iterator, so it has to have some aggregate function. You could use MIN(), MAX() whatever, in theory... it should not matter. I use VALUES() because if it matches more than 1 row, it will blow up, which sounds good to me. (better than having no idea something weird happened...)
 
Upvote 0
Thanks for the reminder scottsen... RELATED was indeed what I was looking for (still reading Rob's book...)
 
Upvote 0
scottsen Would =RELATED(Price_tbl[Price])*[Qty] in the table Sales be considered efficient? Or it is better to use a column with related only and a column with sumx?
 
Upvote 0
That's a question for the ages, cyrilbrd. :)

If you are doing this on a small table... say 100k rows or less, i wouldn't even spend brain cycles on this. Do the calc column multiplication and move on.

More than that, I would probably do it in the database (assuming that was my source data). While I would still have an extra column... at least it would be compressed. (Calc columns are generally NOT compressed).

If we started getting over 1 million rows, you are well into "test it" land. It may be that the overhead of extra space taken up by the column... is worse than the extra calculation taken up by the SUMX. But there are no hard and fast rules there.
 
Upvote 0
Mmmh, yes I can imagine that, volume of data would definitely call for different approaches... Noted re SUMX, will look into that further.


Thanks gain Scottsen, looking forward to read your next intervention on PowerPivotPro...
 
Upvote 0
Thanks scottsen and cyrilbrd, that helped enormously. I now realise that I need to understand DAX functions as well as I understand Excel functions.

scottsen forgive me but I didnt follow the SUMX and VALUE part as the price table has unique "link" vales even though Sales links are not. I found that by using =RELATED('Price'[Price])*[Qty]) in the Sales table did the job. Is this wrong? Error prone?
 
Upvote 0
I think that is likely the best way to solve it :)

I wrote lots of text trying to describe the difference between a measure (calculated field) and a calculated column... because based on your error... it looked like you were trying to write the former.

But your answer here is clearly a calc column, and a good way to solve it.
 
Upvote 0

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