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
JLMJ
New Member

Getting consistent customers

Hi!

Im a beginner in PowerBI.

 

I need help in creating this view.

Suppose I have this transactional dataset.

 

JLMJ_0-1659925251044.png

 

What I want to get are the counts of customers with consistent transaction for the past 3 months, 6 months, and even 12 months (relative to the month of reference and category)

 

Here's the result I would want to achieve:

JLMJ_1-1659925325796.png

 

I think this can be resolved through DAX but let I am open with any suggestions.

 

Thanks!!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below.

 

Untitled.png

 

 

Past 3 months consistent customers count: = 
VAR _selectedcategory =
    VALUES ( Category[Category] )
VAR _pastmonthsnumberselect = 3
VAR _selectedmonthenddate =
    MAX ( 'Calendar'[End of Month] )
VAR _startdate =
    EOMONTH ( _selectedmonthenddate, - _pastmonthsnumberselect ) + 1
VAR _monthlycalendartable =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= _selectedmonthenddate
                && 'Calendar'[Date] >= _startdate
        ),
        'Calendar'[Month-Year]
    )
VAR _newtable =
    FILTER (
        SUMMARIZE (
            ADDCOLUMNS (
                FILTER (
                    SUMMARIZE (
                        ALL ( Data ),
                        Category[Category],
                        Customer[Cust_ID],
                        'Calendar'[Month-Year]
                    ),
                    'Calendar'[Month-Year]
                        IN _monthlycalendartable
                        && Category[Category] IN _selectedcategory
                ),
                "@amountsum", CALCULATE ( SUM ( Data[Amount] ) )
            ),
            Customer[Cust_ID],
            'Calendar'[Month-Year],
            [@amountsum]
        ),
        [@amountsum] <> 0
    )
VAR _groupbycustomer =
    FILTER (
        GROUPBY (
            _newtable,
            Customer[Cust_ID],
            "@monthcount", SUMX ( CURRENTGROUP (), 1 )
        ),
        [@monthcount] >= _pastmonthsnumberselect
    )
VAR _result =
    COUNTROWS ( _groupbycustomer )
RETURN
    _result + 0

 

 

 

Past 6 months consistent customers count: = 
VAR _selectedcategory =
    VALUES ( Category[Category] )
VAR _pastmonthsnumberselect = 6
VAR _selectedmonthenddate =
    MAX ( 'Calendar'[End of Month] )
VAR _startdate =
    EOMONTH ( _selectedmonthenddate, - _pastmonthsnumberselect ) + 1
VAR _monthlycalendartable =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= _selectedmonthenddate
                && 'Calendar'[Date] >= _startdate
        ),
        'Calendar'[Month-Year]
    )
VAR _newtable =
    FILTER (
        SUMMARIZE (
            ADDCOLUMNS (
                FILTER (
                    SUMMARIZE (
                        ALL ( Data ),
                        Category[Category],
                        Customer[Cust_ID],
                        'Calendar'[Month-Year]
                    ),
                    'Calendar'[Month-Year]
                        IN _monthlycalendartable
                        && Category[Category] IN _selectedcategory
                ),
                "@amountsum", CALCULATE ( SUM ( Data[Amount] ) )
            ),
            Customer[Cust_ID],
            'Calendar'[Month-Year],
            [@amountsum]
        ),
        [@amountsum] <> 0
    )
VAR _groupbycustomer =
    FILTER (
        GROUPBY (
            _newtable,
            Customer[Cust_ID],
            "@monthcount", SUMX ( CURRENTGROUP (), 1 )
        ),
        [@monthcount] >= _pastmonthsnumberselect
    )
VAR _result =
    COUNTROWS ( _groupbycustomer )
RETURN
    _result + 0

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

 

# Detension = 
VAR __n = MAX( SPAN[Consecutive] )
VAR __p = DATESINPERIOD( DATES[Date], MAX( DATES[Date] ), - __n, MONTH )
RETURN
    COUNTROWS(
        FILTER(
            VALUES( DATA[Cust_ID] ),
            CALCULATE( DISTINCTCOUNT( DATES[Yr-Mn] ), CALCULATETABLE( DATA, __p ) ) = __n
        )
    ) + 0

 

Record_2022_08_08_15_05_56_764.gif


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below.

 

Untitled.png

 

 

Past 3 months consistent customers count: = 
VAR _selectedcategory =
    VALUES ( Category[Category] )
VAR _pastmonthsnumberselect = 3
VAR _selectedmonthenddate =
    MAX ( 'Calendar'[End of Month] )
VAR _startdate =
    EOMONTH ( _selectedmonthenddate, - _pastmonthsnumberselect ) + 1
VAR _monthlycalendartable =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= _selectedmonthenddate
                && 'Calendar'[Date] >= _startdate
        ),
        'Calendar'[Month-Year]
    )
VAR _newtable =
    FILTER (
        SUMMARIZE (
            ADDCOLUMNS (
                FILTER (
                    SUMMARIZE (
                        ALL ( Data ),
                        Category[Category],
                        Customer[Cust_ID],
                        'Calendar'[Month-Year]
                    ),
                    'Calendar'[Month-Year]
                        IN _monthlycalendartable
                        && Category[Category] IN _selectedcategory
                ),
                "@amountsum", CALCULATE ( SUM ( Data[Amount] ) )
            ),
            Customer[Cust_ID],
            'Calendar'[Month-Year],
            [@amountsum]
        ),
        [@amountsum] <> 0
    )
VAR _groupbycustomer =
    FILTER (
        GROUPBY (
            _newtable,
            Customer[Cust_ID],
            "@monthcount", SUMX ( CURRENTGROUP (), 1 )
        ),
        [@monthcount] >= _pastmonthsnumberselect
    )
VAR _result =
    COUNTROWS ( _groupbycustomer )
RETURN
    _result + 0

 

 

 

Past 6 months consistent customers count: = 
VAR _selectedcategory =
    VALUES ( Category[Category] )
VAR _pastmonthsnumberselect = 6
VAR _selectedmonthenddate =
    MAX ( 'Calendar'[End of Month] )
VAR _startdate =
    EOMONTH ( _selectedmonthenddate, - _pastmonthsnumberselect ) + 1
VAR _monthlycalendartable =
    SUMMARIZE (
        FILTER (
            ALL ( 'Calendar' ),
            'Calendar'[Date] <= _selectedmonthenddate
                && 'Calendar'[Date] >= _startdate
        ),
        'Calendar'[Month-Year]
    )
VAR _newtable =
    FILTER (
        SUMMARIZE (
            ADDCOLUMNS (
                FILTER (
                    SUMMARIZE (
                        ALL ( Data ),
                        Category[Category],
                        Customer[Cust_ID],
                        'Calendar'[Month-Year]
                    ),
                    'Calendar'[Month-Year]
                        IN _monthlycalendartable
                        && Category[Category] IN _selectedcategory
                ),
                "@amountsum", CALCULATE ( SUM ( Data[Amount] ) )
            ),
            Customer[Cust_ID],
            'Calendar'[Month-Year],
            [@amountsum]
        ),
        [@amountsum] <> 0
    )
VAR _groupbycustomer =
    FILTER (
        GROUPBY (
            _newtable,
            Customer[Cust_ID],
            "@monthcount", SUMX ( CURRENTGROUP (), 1 )
        ),
        [@monthcount] >= _pastmonthsnumberselect
    )
VAR _result =
    COUNTROWS ( _groupbycustomer )
RETURN
    _result + 0

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

amitchandak
Super User
Super User

@JLMJ , Have date table, and have month year in your table/sales table

 

Sales Month = format([Date], "YYYYMM")

 

Rolling 3= CALCULATE(distinctcount(Sales[Sales Month]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-3,MONTH))

 

Continue in the last three months

countx(filter(Values(Sales[Customer]) , [Rolling 3]=3) , [Customer])

 

Same way change rolling to 6, 12 to get the number

 


To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.