Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Roseventura
Responsive Resident
Responsive Resident

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 5
Roseventura
Responsive Resident
Responsive Resident

I need to submit sample data.  Please do not close this issue.

Anonymous
Not applicable

Hi @Roseventura ,

 

Any updates?

 

You could refer to the blogs below to know How to provide sample data in the Power BI Forum and How to Get Your Question Answered Quickly

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

Writing measures is the correct approach.  Share some data and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
AlexisOlson
Super User
Super User

A calculated table cannot be dynamic based on user selection since calculated tables (and calculated columns) are only calculated once each time the data model is loaded or refreshed rather than in response to slicers or filters from the report page.

 

On the other hand, this is what measures are designed to do. So your ultimate goal is very likely possible--you just need a slightly different approach.

VahidDM
Super User
Super User

HI @Roseventura 

 

Read this : 

https://radacad.com/caution-when-using-variables-in-dax-and-power-bi

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors