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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
syedshah01
Regular Visitor

Calcualting repeat cusotmers for each month and then totaling it up for all months

Hi,

 

I have a requirement where for each month starting six months ago until current selected month, it should calculate the repeat customers that purchased in any previous months and then total up the repeat customers for all six months. For example

 

There are ten customers, A, B, C, D, E, F, G, H, I, J. Customer A, B, C, D and E purchased a product in December. In January, we have D, E, F cusotmers so we have two repeat customers. In Feb, A, H and I purchased. Since A, purchased previously (Dec), we have 1 repeat cusotmer in Feb. In March, we have B, E, H and J so we have three repeat customers and so on. We calculate this until current month. Eventually, we total up the repeat for all months.

 

How can I calcualte this using DAX?

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

Hi @syedshah01 ,

I create a table as you mentioned.

vyilongmsft_0-1721718876064.png

Then I create three measures and here are the DAX codes.

12m-1m = 
CALCULATE(
    DISTINCTCOUNT('Table'[CustomerID]),
    FILTER(
        'Table',
        (
            NOT(ISBLANK('Table'[12m])) && NOT(ISBLANK('Table'[1m]))
        )
    )
)

vyilongmsft_1-1721718943251.png

12m-2m = 
CALCULATE(
    DISTINCTCOUNT('Table'[CustomerID]),
    FILTER(
        'Table',
        (
            NOT(ISBLANK('Table'[12m])) && NOT(ISBLANK('Table'[2m]))
        ) || (
            NOT(ISBLANK('Table'[1m])) && NOT(ISBLANK('Table'[2m]))
        )
    )
)

vyilongmsft_2-1721718986293.png

12m-3m = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustomerID] ),
    FILTER (
        'Table',
        ( NOT ( ISBLANK ( 'Table'[12m] ) ) && NOT ( ISBLANK ( 'Table'[3m] ) ) )
            || ( NOT ( ISBLANK ( 'Table'[1m] ) ) && NOT ( ISBLANK ( 'Table'[3m] ) ) )
            || ( NOT ( ISBLANK ( 'Table'[2m] ) ) && NOT ( ISBLANK ( 'Table'[3m] ) ) )
    )
)

vyilongmsft_3-1721719318004.png

Finally you can count all the measures.

Total = 'Table'[12m-1m] + 'Table'[12m-2m] +'Table'[12m-3m]

vyilongmsft_4-1721719493337.png

 

 

 

Best Regards

Yilong Zhou

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-yilong-msft
Community Support
Community Support

Hi @syedshah01 ,

I create a table as you mentioned.

vyilongmsft_0-1721718876064.png

Then I create three measures and here are the DAX codes.

12m-1m = 
CALCULATE(
    DISTINCTCOUNT('Table'[CustomerID]),
    FILTER(
        'Table',
        (
            NOT(ISBLANK('Table'[12m])) && NOT(ISBLANK('Table'[1m]))
        )
    )
)

vyilongmsft_1-1721718943251.png

12m-2m = 
CALCULATE(
    DISTINCTCOUNT('Table'[CustomerID]),
    FILTER(
        'Table',
        (
            NOT(ISBLANK('Table'[12m])) && NOT(ISBLANK('Table'[2m]))
        ) || (
            NOT(ISBLANK('Table'[1m])) && NOT(ISBLANK('Table'[2m]))
        )
    )
)

vyilongmsft_2-1721718986293.png

12m-3m = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[CustomerID] ),
    FILTER (
        'Table',
        ( NOT ( ISBLANK ( 'Table'[12m] ) ) && NOT ( ISBLANK ( 'Table'[3m] ) ) )
            || ( NOT ( ISBLANK ( 'Table'[1m] ) ) && NOT ( ISBLANK ( 'Table'[3m] ) ) )
            || ( NOT ( ISBLANK ( 'Table'[2m] ) ) && NOT ( ISBLANK ( 'Table'[3m] ) ) )
    )
)

vyilongmsft_3-1721719318004.png

Finally you can count all the measures.

Total = 'Table'[12m-1m] + 'Table'[12m-2m] +'Table'[12m-3m]

vyilongmsft_4-1721719493337.png

 

 

 

Best Regards

Yilong Zhou

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

some_bih
Super User
Super User

Hi @syedshah01 check link with example





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.