Forum Discussion
Error when calculating Returning Customers
- Anonymous1 year ago
Hi EllieSiroco1
Please try this:
Here I create a set of sample:
Then add a calculated column:
Returning Customers = VAR CurrentPeriodStart = DATE ( 2024, 11, 01 ) VAR CurrentPeriodEnd = DATE ( 2024, 12, 31 ) VAR _previousSales2 = CALCULATE ( SUM ( 'orders-web2019'[Sales inc VAT] ), FILTER ( ALLSELECTED ( 'orders-web2019' ), 'orders-web2019'[customer email] = EARLIER ( 'orders-web2019'[customer email] ) && YEAR ( 'orders-web2019'[Order date] ) = YEAR ( EARLIER ( 'orders-web2019'[Order date] ) ) - 1 && MONTH ( 'orders-web2019'[Order date] ) = MONTH ( EARLIER ( 'orders-web2019'[Order date] ) ) ) ) RETURN IF ( 'orders-web2019'[Order date] >= CurrentPeriodStart && 'orders-web2019'[Order date] <= CurrentPeriodEnd, IF ( _previousSales2 > 0 && 'orders-web2019'[Sales inc VAT] > 0, "Returning", "New" ) )The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - 1 year ago
Sorry I think I misunderstood you before.
I think this simply solution will do what you you want ...
Create 4 measures ...
Has NovDec2023 sales = // create a temp file of dates in range VAR mydates = FILTER('Calendar', 'Calendar'[Date] >= DATE(2023,11,01) && 'Calendar'[Date] <= DATE(2023,12,31)) RETURN // return 1 if there were any sales within date range CALCULATE( INT(NOT(ISEMPTY(Sales))), mydates )Has NovDec2024 sales = // create a temp file of dates in range VAR mydates = FILTER('Calendar', 'Calendar'[Date] >= DATE(2024,11,01) && 'Calendar'[Date] <= DATE(2024,12,31)) RETURN // return 1 if there were any sales within date range CALCULATE( INT(NOT(ISEMPTY(Sales))), mydates )New customers = // create temp file of qualifiying customers var mysubset = FILTER(VALUES(Sales[CustomerKey]), [Has NovDec2023 sales] = 0 && [Has NovDec2024 sales] = 1) RETURN // count the rows COUNTROWS(mysubset)Returning customer = // create temp file of qualifiying customers var mysubset = FILTER(VALUES(Sales[CustomerKey]), [Has NovDec2023 sales] = 1 && [Has NovDec2024 sales] = 1) RETURN // count the rows COUNTROWS(mysubset)Please click the [accept solution] and thumbs up button. Thank you.
Click here to download PBIX example from Onedrive
speedramps thank you for the solution, I am not entirely sure how to adapt it , as i do not have a "minimum date". I am comparing two very specific periods:
between "01 November 2023 to 31 December 2023" (order date) and the period between the order dates "01 November 2024 to 31 December 2024, rather than the period before a date in the entire calendar
- speedramps1 year agoSuper User
Sorry I think I misunderstood you before.
I think this simply solution will do what you you want ...
Create 4 measures ...
Has NovDec2023 sales = // create a temp file of dates in range VAR mydates = FILTER('Calendar', 'Calendar'[Date] >= DATE(2023,11,01) && 'Calendar'[Date] <= DATE(2023,12,31)) RETURN // return 1 if there were any sales within date range CALCULATE( INT(NOT(ISEMPTY(Sales))), mydates )Has NovDec2024 sales = // create a temp file of dates in range VAR mydates = FILTER('Calendar', 'Calendar'[Date] >= DATE(2024,11,01) && 'Calendar'[Date] <= DATE(2024,12,31)) RETURN // return 1 if there were any sales within date range CALCULATE( INT(NOT(ISEMPTY(Sales))), mydates )New customers = // create temp file of qualifiying customers var mysubset = FILTER(VALUES(Sales[CustomerKey]), [Has NovDec2023 sales] = 0 && [Has NovDec2024 sales] = 1) RETURN // count the rows COUNTROWS(mysubset)Returning customer = // create temp file of qualifiying customers var mysubset = FILTER(VALUES(Sales[CustomerKey]), [Has NovDec2023 sales] = 1 && [Has NovDec2024 sales] = 1) RETURN // count the rows COUNTROWS(mysubset)Please click the [accept solution] and thumbs up button. Thank you.
Click here to download PBIX example from Onedrive