- Microsoft Power BI Cookbook
- Brett Powell
- 143字
- 2025-04-04 18:18:13
Active verus inactive customers
The following example identifies the customers who purchased last year but haven't yet purchased this year.
- Create a measure for missing or inactive customers
- Use DAX variables and time intelligence functions to produce two filtered sets of customer keys.
Count of Last Year Customers ex Current Year =
VAR Today = TODAY() VAR CurrentYear = YEAR(Today) VAR LastYear = YEAR(Today) - 1
VAR LYCustomers =
SUMMARIZE(CALCULATETABLE('Internet Sales',
FILTER(ALL('Date'),'Date'[Calendar Year] = LastYear)),Customer[Customer Alternate Key])
VAR CYCustomers =
SUMMARIZE(CALCULATETABLE('Internet Sales',
FILTER(ALL('Date'),'Date'[Calendar Year] = CurrentYear)),Customer[Customer Alternate Key])
RETURN
CALCULATE(DISTINCTCOUNT(Customer[Customer Alternate Key]),EXCEPT(LYCustomers,CYCustomers))
- Pass the time variables to the CALCULATETABLE() function and then group the keys by SUMMARIZE()
- Visualize the measure in Power BI Desktop

Visualization of Last Year Customer Count excluding Current Year Customers
- A visual level filter applied to the new measure exposes the specific 287 customers without a 2017 purchase yet