mgirvin
Well-known Member
- Joined
- Dec 15, 2005
- Messages
- 1,245
- Office Version
- 365
- Platform
- Windows
Dear Team,
I am creating a Calculated Column to simulate VLOOKUP Approximate Match. The goal of the formula is to retrieve the Cost discount based on number of units sold. I have a table named “disCostDiscounts”, where the first column is Units and the second column is Discounts. The table looks like this:
Units Discounts
0 0
26 0.02
51 0.03
76 0.05
100 0.075
500 0.1
1000 0.15
I also have transactions table named “fSales”, where one of the columns is named Units.
Here is my Calculated Column formula in the “fSales” table:
=CALCULATE(MAX(disCostDiscounts[Discounts]),FILTER(disCostDiscounts,disCostDiscounts[Units]<=fSales[Units]))
My question is this:
1) Can you explain the step-by-step calculating process for this formula?
2) The part that I am not understanding is this: I thought that inside the CALCULATE function, CALCULATE always ran “Filter Context”, so how is it that the formula knows that for “fSales[Units]” it should be doing “Row Context”? Does the fact that the formula is in a Calculated Column which automatically creates “Row Context” override the “Filter Context” inside CALCULATE? Or is this a case where CALCULATE does its “Context Transition”?
Sincerely, Mike "Trying to Learn PowerPivot, but it is Really Hard" Girvin
P.S. I posted this same question at Msdn forums - SQL Server. I am not sure what the online etiquette is for cross posting the same question at different sites is. Is it okay to cross post?
I am creating a Calculated Column to simulate VLOOKUP Approximate Match. The goal of the formula is to retrieve the Cost discount based on number of units sold. I have a table named “disCostDiscounts”, where the first column is Units and the second column is Discounts. The table looks like this:
Units Discounts
0 0
26 0.02
51 0.03
76 0.05
100 0.075
500 0.1
1000 0.15
I also have transactions table named “fSales”, where one of the columns is named Units.
Here is my Calculated Column formula in the “fSales” table:
=CALCULATE(MAX(disCostDiscounts[Discounts]),FILTER(disCostDiscounts,disCostDiscounts[Units]<=fSales[Units]))
My question is this:
1) Can you explain the step-by-step calculating process for this formula?
2) The part that I am not understanding is this: I thought that inside the CALCULATE function, CALCULATE always ran “Filter Context”, so how is it that the formula knows that for “fSales[Units]” it should be doing “Row Context”? Does the fact that the formula is in a Calculated Column which automatically creates “Row Context” override the “Filter Context” inside CALCULATE? Or is this a case where CALCULATE does its “Context Transition”?
Sincerely, Mike "Trying to Learn PowerPivot, but it is Really Hard" Girvin
P.S. I posted this same question at Msdn forums - SQL Server. I am not sure what the online etiquette is for cross posting the same question at different sites is. Is it okay to cross post?