Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi,
I need to calculate the number of customers new in the previous month which have had 2 visits.
Fact table:
I also have a date dimension joined to the fact table which has an active relationship on visit date so TREATAS or USERELATIONSHIP may need to be used.
New customer is defined by their reg date. So the dax should count customers that registered and had two visits in the previous full month.
From the above, only customer 1 should be counted, as customer 2 didn't have a registration date in the previous month.
Can anyone help?
Hi @Anonymous ,
Here are the steps you can follow:
1. Create measure.
Count =
var _table1=
SUMMARIZE(
'Table',
'Table'[Index],'Table'[Customer_ID],'Table'[Reg_date], 'Table'[Visits],'Table'[Visit date],
"1",
COUNTX(FILTER(ALL('Table'),
MONTH('Table'[Reg_date])=MONTH(TODAY())-1&&MONTH('Table'[Visit date])=MONTH(TODAY())-1&&'Table'[Customer_ID]=EARLIER('Table'[Customer_ID])),[Visit date])
)
var _table2=
ADDCOLUMNS(_table1,"2",
IF(
[1]>=2,
CALCULATE(DISTINCTCOUNT('Table'[Customer_ID]),FILTER(ALL('Table'),'Table'[Customer_ID]=MAX('Table'[Customer_ID])&&[1]>=2))))
return
MAXX(_table2,[2])
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @Anonymous ,
Here are the steps you can follow:
1. Create measure.
Measure =
var _lastmonth=MONTH(TODAY())-1
var _count=COUNTX(FILTER(ALL('Table'),
MONTH('Table'[Reg_date])=_lastmonth&&MONTH('Table'[Visit date])=_lastmonth&&'Table'[Customer_ID]=MAX('Table'[Customer_ID])),[Visit date])
return
IF(
_count>=2,
CALCULATE(DISTINCTCOUNT([Customer_ID]),FILTER(ALL('Table'),'Table'[Customer_ID]=MAX('Table'[Customer_ID])&&_count>=2)))
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
I think I can use this if I can put it into a calculated column instead so it acts as a flag. Do I need to change the formula in any way since a calculated column will work on a row by row basis?
Appreciate your help
Hi Liu,
Thanks for the response! Measure works when shown in a table against a set of dates - like the screenshot you provided of it working.
However, it shows blank as standalone in say a card visual. I need it to show a single figure for all customers not on a row by row basis.
Would I need to amend the countx function?
Bump
@amitchandak @tamerj1 hopefully it's okay to tag - any ideas as top authors?
This is what I came up with but seems to show very low numbers