Can I create filter context derived from value of different filter context variable?

watridge

New Member
Joined
Oct 11, 2014
Messages
4
I'm pretty new to Powerpivot and DAX and seem to have got myself stuck. Hoping that the experts can give me a simple fix!

I have a fact table which has two date fields TransactionDate and CustomerStartDate and transaction amounts.
TransactionDate is related to the DimDate table (I use DimDate[Calendar Year])
CustomerStartDate is related to the StDimDate table. (I use StDimDate[SY.Calendar Year])

With this info I can very easily create a simple "cohort analysis" using StDimDate[SY.Calendar Year] as the row headers and DimDate[Calendar Year] for the col headers.

I'm also doing some more detailed Year over Year change calculations and I end up using SUMX to aggregate over customer ID's and sum up only the negative aggregated per customer ID results per YoY change == Downgrades and the Positive aggregated results per customer ID ==Upgrades.

Now comes the part where I am stuck. I want to aggregate only the Upgrades that are from cohorts that are more than 2 years older than "this" year:
Effectively I want to aggregate only when StDimDate[SY.Calendar Year]
However I can't find a way to do the calculation in powerpivot without error messages.

This formula gives me the correct result for the "this year = 2013 =DimDate[Calendar Year]" when I manually enter the value into the calculation:
=SUMX(ALL(combined[tblCustomer#CustomerID]),
CALCULATE(if(AND([DeltaSalesYoY]>0, [test1]>6),[DeltaSalesYoY],0),FILTER(StDimDate,StDimDate[SY.Calendar Year]<2013-1))
)

I'd like to have the calculation work for whatever value is the current context of the DimDate[Calendar Year] when I substitute it in for 2013 in the calculation above -- like this:
Replace: "2013-1"
With: "DimData[Calendar Year]-1"<dimdate[calendar year]-1))
<dimdate[calendar year]-1="" )
<dimdate[calendar year]-1="" )<dimdate[calendar="" )
<dimdate[calendar year]-1))
<dimdate[calendar year]-1)))



However I get the following error message:
"The value for column 'Calendar Year' in table 'DimDate' 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."

I think I must be missing a simple fix (I hope!)

Thanks for your help.

Regards
Pete</dimdate[calendar></dimdate[calendar></dimdate[calendar></dimdate[calendar></dimdate[calendar>
 
Last edited:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I found a way to get it to work. I needed to wrap the formula with something that guarantees that DimData[Calendar Year] only has a single value. So this now works:

=if(MAX(DimDate[Calendar Year])=MIN(DimDate[Calendar Year]),SUMX(ALL(combined[tblCustomer#CustomerID]),
CALCULATE(if(AND([DeltaSalesYoY]>0, [test1]>6),[DeltaSalesYoY],0),FILTER(StDimDate,StDimDate[SY.Calendar Year]<Max(DimDate[Calendar Year])-1))
),0)

Wondering if there is a way to do this more efficiently?

Thanks
Pete
 
Upvote 0
Actually -- I over thought the issue -- this simpler verison works fine:

=SUMX(ALL(combined[tblCustomer#CustomerID]),
CALCULATE(if(AND([DeltaSalesYoY]>0, [test1]>6),[DeltaSalesYoY],0),FILTER(StDimDate,StDimDate[SY.Calendar Year]<Max(DimDate[Calendar Year])-1))
)
 
Upvote 0
I didn't actually read your post since found your own answer (go you!) but the IF (Max() = MIN()) ... you would typically do IF (HASONEVALUE()) :)
 
Upvote 0

Forum statistics

Threads
1,224,044
Messages
6,176,048
Members
452,701
Latest member
rfhandel

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