Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
I have the following data structure:
Table: transactions
Ref - Subscription reference
Date - Date of the order
I want to calculate some key metrics, for example, churn rate or count of new users. To achieve this, I need to get data for the previous period and compare it to the current period. In SQL I can do left/right join but in DAX I cannot figure out how to use Except function correctly.
Looks like it works for new subscriptions, but if I cannot figure out how to change it to find lost subscriptions:
NewSubscriptions = IF( ISFILTERED('transactions'[Date]); ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."); VAR _CURRENT = CALCULATETABLE(DISTINCT(transactions[Ref]);FILTER(transactions;transactions[Date])) VAR _PREV = CALCULATETABLE(DISTINCT(transactions[Ref]);DATEADD('transactions'[Date].[Date]; -1; MONTH)) RETURN COUNTROWS(EXCEPT(_CURRENT;_PREV)) )
Solved! Go to Solution.
Looks like I figured out how to make it works:
NewSubscriptions = IF( ISFILTERED('transactions'[Date]); ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."); VAR _CURRENT = CALCULATETABLE(DISTINCT(transactions[Ref]);FILTER(transactions;transactions[Date])) VAR _PREV = CALCULATETABLE(DISTINCT(transactions[Ref]);DATEADD('transactions'[Date].[Date]; -1; MONTH)) RETURN COUNTROWS(EXCEPT(_CURRENT;_PREV)) )
LostSubscriptions = IF( ISFILTERED('transactions'[Date]); ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."); VAR _CURRENT = CALCULATETABLE(DISTINCT(transactions[Ref]);FILTER(transactions;transactions[Date])) VAR _PREV = CALCULATETABLE(DISTINCT(transactions[Ref]);DATEADD('transactions'[Date].[Date]; -1; MONTH)) RETURN COUNTROWS(EXCEPT(_PREV;_CURRENT)) )
Looks like I figured out how to make it works:
NewSubscriptions = IF( ISFILTERED('transactions'[Date]); ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."); VAR _CURRENT = CALCULATETABLE(DISTINCT(transactions[Ref]);FILTER(transactions;transactions[Date])) VAR _PREV = CALCULATETABLE(DISTINCT(transactions[Ref]);DATEADD('transactions'[Date].[Date]; -1; MONTH)) RETURN COUNTROWS(EXCEPT(_CURRENT;_PREV)) )
LostSubscriptions = IF( ISFILTERED('transactions'[Date]); ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."); VAR _CURRENT = CALCULATETABLE(DISTINCT(transactions[Ref]);FILTER(transactions;transactions[Date])) VAR _PREV = CALCULATETABLE(DISTINCT(transactions[Ref]);DATEADD('transactions'[Date].[Date]; -1; MONTH)) RETURN COUNTROWS(EXCEPT(_PREV;_CURRENT)) )
User | Count |
---|---|
59 | |
59 | |
56 | |
38 | |
29 |
User | Count |
---|---|
77 | |
62 | |
45 | |
40 | |
39 |