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
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.
thank you very much Anonymous this works for me