Forum Discussion
DAX - Customer retention
- 4 years ago
Hi Diego_Vialle
Please try the following code. To be honest I have no idea whether it works or not. However I tried to optimize it only by sense as I have no data to work with and measure the actual performance. This is a heavy code which in total requires a great number of context transitions and multiple iterations over the complete table. This iteration cannot be avoided otherwise there is no other way to gain access to each individual date which is required to calculate the period gap between each two consecutive transactions of the same customer. You might find it a bet complex but in fact it is simple and I hope it works.
Further you shall be able to use the same code to flag the customers who matches this criteria with the flexibility to filter different ranges of date (You can use a time slider based on dCalendar[Date] to select start and end dates of the selected period)
Teste aula = SUMX ( CALCULATETABLE ( VALUES ( SBOPRODMS[Código do cliente] ), SBOPRODMS[Documento] = "Nota fiscal de saída" ), VAR CurrentCustomerTable = CALCULATETABLE ( SBOPRODMS, SBOPRODMS[Documento] = "Nota fiscal de saída" ) VAR T1 = ADDCOLUMNS ( CurrentCustomerTable, "Period", VAR CurrentDate = SBOPRODMS[Data Base] VAR PreviousDate = MAXX ( FILTER ( CurrentCustomerTable, SBOPRODMS[Data Base] < CurrentDate ), SBOPRODMS[Data Base] ) RETURN IF ( NOT ISBLANK ( PreviousDate ), DATEDIFF ( PreviousDate, CurrentDate, DAY ) ) ) VAR MaxiDisengagementPeriod = MAXX ( T1, [Period] ) RETURN IF ( MaxiDisengagementPeriod > 365, 1 ) )
Hi, Diego_Vialle
Can you provide some sample data or simple pbix files? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures.
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.