Created
August 8, 2016 00:30
-
-
Save mlongoria/ae76049dcfeb35dba0bcc4cda02707d4 to your computer and use it in GitHub Desktop.
Shows the calculation of lost customers based upon sales fact using DAX for SSAS Tabular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lost Customers := | |
IF ( | |
NOT ( | |
MIN ( 'Date'[Full Date] ) | |
> CALCULATE ( MAX ( Sales[Invoice Date] ), ALL ( Sales ) ) | |
), | |
COUNTROWS ( | |
FILTER ( | |
ADDCOLUMNS ( | |
FILTER ( | |
CALCULATETABLE ( | |
ADDCOLUMNS ( | |
CALCULATETABLE ( | |
VALUES ( Customer[Customer No] ), Sales ), | |
"CustomerLostDate", CALCULATE ( | |
MAX ( Sales[Invoice Date] ), | |
ALLEXCEPT ( Customer, Customer[Customer No] ) | |
) | |
+ [Lost Days Limit] | |
), | |
FILTER ( | |
ALL ( 'Date' ), | |
AND ( | |
'Date'[Full Date] < MIN ( 'Date'[Full Date] ), | |
'Date'[Full Date] >= | |
MIN ( 'Date'[Full Date] ) - [Lost Days Limit] | |
) | |
) | |
), | |
AND ( | |
AND ( | |
[CustomerLostDate] >= MIN ( 'Date'[Full Date] ), | |
[CustomerLostDate] <= MAX ( 'Date'[Full Date] ) | |
), | |
[CustomerLostDate] <= | |
CALCULATE ( MAX ( Sales[Invoice Date] ), ALL ( Sales ) ) | |
) | |
), | |
"FirstBuyInPeriod", CALCULATE ( MIN ( Sales[Invoice Date] ) ) | |
), | |
OR ( | |
ISBLANK ( [FirstBuyInPeriod] ), | |
[FirstBuyInPeriod] > [CustomerLostDate] | |
) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment