Search code examples
ssasdaxssas-tabular

Creating a calculated column (not aggregate) that changes value based on context SSAS tabular DAX


Data: I have a single row that represents an annual subscription to a product, it has an overall startDate and endDate, there is also third date which is startdate + 1 month called endDateNew. I also have a non-related date table (called table X).

Output I'm looking for: I need a new column called Categorisation that will return 'New' if the date selected in table X is between startDate and endDateNew and 'Existing' if the date is between startDate and endDate.

Problem: The column seems to evaluate immediately without taking in to account the date context from the non-related date table - I kinda expected this to happen in visual studio (where it assumes the context is all records?) but when previewing in Excel it carries through this same value through.

The bit that is working:I have an aggregate (an active subscriber count) that correctly counts the subscription as active over the months selected in Table X.

The SQL equivalent on an individual date:

case 
 when '2015-10-01' between startDate and endDateNew then 'New'
 when '2015-10-01' < endDate then 'Existing'
end as Category

where the value would be calculated for each date in table X

Thanks!

Ross


Solution

  • Calculated columns are only evaluated at model refresh/process time. This is by design. There is no way to make a calculated column change based on run-time changes in filter context from a pivot table.