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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
pbi_baller
Frequent Visitor

AVG New Customer Spend - DAX

Hi,

 

I need to calculate the average spend for new customers in the previous month. However, it needs to be only for customers that have had at least 2 visits in that previous month. 

 

Formula: Spend of new customers with >=2 visits in previous month / no. of new customers with >=2 visits in previous month

 

Fact table below - it also has a column for spend

 

Fact table:

pbi_baller_0-1655814232766.png

 

 

Date dimension is joined on visit date. 

 

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.

 

Any help would be appreciated. Thanks!

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @pbi_baller ,

 

Maybe you can try this code:

AVG =
AVERAGEX (
    FILTER (
        CALCULATETABLE (
            SUMMARIZE (
                FILTER ( 'FactTable', MONTH ( [Reg_date] ) = MONTH ( [Visits date] ) ),
                [Customer_ID],
                "count", IF ( COUNTROWS ( 'FactTable' ) >= 2, 1, 0 ),
                "spend", SUM ( FactTable[Spend] )
            ),
            PREVIOUSMONTH ( 'Calendar'[Date] )
        ),
        [count] <> 0
    ),
    [spend]
)

Result:

vchenwuzmsft_0-1656059665557.png

 

Pbix file in the end you can refer.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @pbi_baller ,

 

Maybe you can try this code:

AVG =
AVERAGEX (
    FILTER (
        CALCULATETABLE (
            SUMMARIZE (
                FILTER ( 'FactTable', MONTH ( [Reg_date] ) = MONTH ( [Visits date] ) ),
                [Customer_ID],
                "count", IF ( COUNTROWS ( 'FactTable' ) >= 2, 1, 0 ),
                "spend", SUM ( FactTable[Spend] )
            ),
            PREVIOUSMONTH ( 'Calendar'[Date] )
        ),
        [count] <> 0
    ),
    [spend]
)

Result:

vchenwuzmsft_0-1656059665557.png

 

Pbix file in the end you can refer.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

pbi_baller
Frequent Visitor

Bumping the post. Can anyone help? Thanks

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors