Forum Discussion

Roseventura's avatar
Roseventura
Responsive Resident
4 years ago

Using VARS with CALCULATETABLE

Could someone please explain to me why this works:

 

LastPurchaseDates =
VAR Churnvalue = 365
RETURN
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(
Shipments,
Customers[CUST_CODE],
"Total Sales", [Total Sales]
),
"LastPurchaseDate", CALCULATE(MAX( Shipments[Ship Date] ))),
Shipments[Ship Date] < today()-churnvalue
)

 

But this does NOT:

 

LastPurchaseDates =
VAR ChurnvalueSELECTEDVALUE('Churn Time Period'[Churn Time Period])
RETURN
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE(
Shipments,
Customers[CUST_CODE],
"Total Sales", [Total Sales]
),
"LastPurchaseDate", CALCULATE(MAX( Shipments[Ship Date] ))),
 
Shipments[Ship Date] < today()-churnvalue
)
 
I need to reference the Chur Time Period Value as that can be changed by a user. I can't get this to work
unless I hard-code '365' into the measure.
 
I basically need a table showing the Customer Code, the last purchase date (Ship date), and the total Sales, but I only want the table to return Customers who have not purchased anything in over "N" time period (Churn Time Period Value), selected by user.
 
How can I get this to work?
 
Thanks.
 
 

5 Replies