Forum Discussion
Anonymous
5 years agoNot applicable
Cohort Analysis Revenue
Hi All - I'm stuck on developing a cohort analysis. I'm looking for a measure that will calculate the Revenue generated 0-12 months after the cohort date according to my column values. I've watched...
- Anonymous5 years ago
// original Cohort Revenue = VAR CohortStartMonth = SELECTEDVALUE( 'Transactions'[Cohort] ) VAR CurrentMonth = EOMONTH( CohortStartMonth, SELECTEDVALUE( 'Periods Out'[Value] ) ) VAR TransactionsInCohortPeriod = // You should never attempt a filter over // a fact table involving RELATED. This kills // performance because RELATED uses // CALCULATE behind the scenes and this // in turn effects context transition which // makes your system die... as you've witnessed. FILTER( 'Transactions', RELATED( 'Date'[EndOfMonth] ) = CurrentMonth ) VAR Invoices = // SUMMARIZE should never be used to do // any calculations in it. NEVER. There are myriads // of reasons but I don't have time to explain. // SUMMARIZE is safe only if you do grouping and // nothing else. On top of that, it looks like this // summarization is completely redundant since // later on you do a SUMX over the total column // anyway. Partitioning the table by PartnerID // is also totally useless in this case because of // the final summation. SUMMARIZE( TransactionsInCohortPeriod, 'Transactions'[PartnerID], "Invoice Total", SUMX( 'Transactions', Transactions[amount] ) ) RETURN SUMX( Invoices, [Invoice Total] ) // Here's probably what you want: [Cohort Revenue] = VAR CurrentMonth = EOMONTH( SELECTEDVALUE( 'Transactions'[Cohort] ), SELECTEDVALUE( 'Periods Out'[Value] ) ) VAR InvoicesTotal = calculate( sum( Transactions[amount] ), keepfilters( 'Date'[EndOfMonth] = CurrentMonth ) ) return InvoicesTotal
Anonymous
5 years agoNot applicable
I've seen so many cohort analyses on the Power BI Community Forums (and there will also probably be many in the PBI Gallery) that it would be a matter of minutes to find something that suits your needs. Please use the Search box...
Anonymous
5 years agoNot applicable
I figured out a measure to work with my sample dataset. However, when I run the query with my actual dataset, I receive an error that the calculation is too memory intensive. Do you have any suggestions on how to optimize the DAX here for a large dataset?
This is my sample model.
This is my measure: it works with my sample dataset, not my actual dataset.
Cohort Revenue =
VAR CohortStartMonth =
SELECTEDVALUE ( 'Transactions'[Cohort] )
VAR CurrentMonth =
EOMONTH(CohortStartMonth, SELECTEDVALUE ( 'Periods Out'[Value] ) )
VAR TransactionsInCohortPeriod =
FILTER(
'Transactions',
RELATED('Date'[EndOfMonth]) = CurrentMonth
)
VAR Invoices =
SUMMARIZE(
TransactionsInCohortPeriod,
'Transactions'[PartnerID],
"Invoice Total", SUMX('Transactions', Transactions[amount])
)
RETURN
SUMX(Invoices, [Invoice Total])
This is the error I get with my actual datset.