Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Calculate all new customers with a second visit

Hi,

 

I need to calculate the number of customers new in the previous month which have had 2 visits.

 

Fact table:

pbi_baller_1-1655475733465.png

 

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?

 

 

6 REPLIES 6
Anonymous
Not applicable

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:

vyangliumsft_0-1655803793329.png

 

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

Anonymous
Not applicable

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:

vyangliumsft_0-1655793969086.png

 

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

Anonymous
Not applicable

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

Anonymous
Not applicable

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?

Anonymous
Not applicable

Bump

Anonymous
Not applicable

@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

 

VAR _table = CALCULATETABLE(Fact_table, TREATAS(VALUES(dim.date[date]), Fact_table[reg_date]), previousmonth(LASTDATE(dim.date[date])) )
 
VAR _summary = FILTERSUMMARIZE_table, Fact_table[Customer_id], "c", COUNT(Fact_table[visits]) ), [c]>=2)
 
RETURN
COUNTROWS( _summary)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.