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
ClaireBear
Helper I
Helper I

Purchase Frequency - Customers with 0, 1,2,3,4 or more transactions for current month

Hello, 

I am having trouble with frequency calculations. Transaction Frequency.JPGI need to create a table counting the number of customers with 0 transactions or 1 or 2 or 3 for the current month, the previous month and include a month over month % trend. I created a table which includes the metrics i must report on but cant get my calculations correct, or link them to my created table. The exisiting tables i have are Dimension Date and Fact Sales. Below are some of the Dax calculations im using:

 

Total Transactions = DISTINCTCOUNT('Fact Sales'[ID])
Current Month Transactions = CALCULATE([Total Transactions],FILTER('Fact Sales',MONTH('Fact Sales'[TransactionDateTime].[Date])=MONTH(TODAY())))
Previous Month Transactions = var current_month= MONTH(TODAY()) return
CALCULATE([Total Transactions],FILTER('Fact Sales',MONTH('Fact Sales'[transactiondatetime].[date])=current_month -1))

 

Any help would be greatly appreciated 🙂 

 

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

HI @ClaireBear ,

I modify your formulas and it can display the current and previous transactions count based on dimension date.

 

Current Month Transactions =
CALCULATE (
    [Total Transactions],
    FILTER (
        ALLSELECTED ( 'Fact Sales' ),
        DATEVALUE ( 'Fact Sales'[TransactionDateTime] )
            IN VALUES ( 'Dimension Date'[Date] )
    )
)

Previous Month Transactions =
CALCULATE (
    [Total Transactions],
    FILTER (
        ALLSELECTED ( 'Fact Sales' ),
        DATEVALUE ( 'Fact Sales'[transactiondatetime] )
            IN DATEADD ( VALUES ( 'Dimension Date'[Date] ), -1, MONTH )
    )
)

MOM Transaction Trend % =
VAR result =
    DIVIDE ( [Current Month Transactions], [Previous Month Transactions], BLANK () )
RETURN
    IF ( result <> BLANK (), result - 1 )

 

11.png

For transaction group, you can refer to the following steps:

1. Create a summarize table with date, member id, count.

 

Table = 
SUMMARIZE (
    ADDCOLUMNS (
        'Fact Sales',
        "Year", YEAR ( [TransactionDateTime] ),
        "Month", MONTH ( [TransactionDateTime] )
    ),
    [Year],
    [Month],
    [MemberID],
    "Count", COUNTROWS(VALUES( ( 'Fact Sales'[TransactionID] )))
)

 

2. Write measures to matched members based on the current date.

 

T0 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _prevMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( ALL('Table'), [Year] * 100 + [Month] < _current )
    )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS ( EXCEPT ( _prevMember,_currMember  ) )+0

T1 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] = 1 )
    )

T2 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] = 2 )
    )

T3 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] = 3 )
    )
T4 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] >= 4 )
    )

 

3. Create a table visual with date fields and measures.

12.png

Notice: I also attached the sample file below.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

HI @ClaireBear ,

I modify your formulas and it can display the current and previous transactions count based on dimension date.

 

Current Month Transactions =
CALCULATE (
    [Total Transactions],
    FILTER (
        ALLSELECTED ( 'Fact Sales' ),
        DATEVALUE ( 'Fact Sales'[TransactionDateTime] )
            IN VALUES ( 'Dimension Date'[Date] )
    )
)

Previous Month Transactions =
CALCULATE (
    [Total Transactions],
    FILTER (
        ALLSELECTED ( 'Fact Sales' ),
        DATEVALUE ( 'Fact Sales'[transactiondatetime] )
            IN DATEADD ( VALUES ( 'Dimension Date'[Date] ), -1, MONTH )
    )
)

MOM Transaction Trend % =
VAR result =
    DIVIDE ( [Current Month Transactions], [Previous Month Transactions], BLANK () )
RETURN
    IF ( result <> BLANK (), result - 1 )

 

11.png

For transaction group, you can refer to the following steps:

1. Create a summarize table with date, member id, count.

 

Table = 
SUMMARIZE (
    ADDCOLUMNS (
        'Fact Sales',
        "Year", YEAR ( [TransactionDateTime] ),
        "Month", MONTH ( [TransactionDateTime] )
    ),
    [Year],
    [Month],
    [MemberID],
    "Count", COUNTROWS(VALUES( ( 'Fact Sales'[TransactionID] )))
)

 

2. Write measures to matched members based on the current date.

 

T0 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _prevMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( ALL('Table'), [Year] * 100 + [Month] < _current )
    )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS ( EXCEPT ( _prevMember,_currMember  ) )+0

T1 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] = 1 )
    )

T2 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] = 2 )
    )

T3 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] = 3 )
    )
T4 = 
VAR _current =
    MAX ( 'Table'[Year] ) * 100
        + MAX ( 'Table'[Month] )
VAR _currMember =
    CALCULATETABLE (
        VALUES ( 'Table'[MemberID] ),
        FILTER ( 'Table', [Year] * 100 + [Month] = _current )
    )
RETURN
    COUNTROWS (
        FILTER ( ALLSELECTED ( 'Table' ), [MemberID] IN _currMember && [Count] >= 4 )
    )

 

3. Create a table visual with date fields and measures.

12.png

Notice: I also attached the sample file below.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Try changing your formulas:

 
Current Month Transactions = CALCULATE(DISTINCTCOUNT('Fact Sales'[ID]),PARALLELPERIOD('Fact Sales'[TransactionDateTime],0,MONTH))
Previous Month Transactions = CALCULATE(DISTINCTCOUNT('Fact Sales'[ID]),PREVIOUSMONTH('Fact Sales'[transactiondatetime]))

Hi  Icespedes,

i tried your suggestion and unfortunately this is not working, i need to link the table i created (transaction frequency) to the measures by current month, previous month and % change. This is to calculate what percentage of total customers had 0 transactions for the current month, how many had 0 transactions for the previous month and what is the difference. Then, how many customers had only 1 transaction for the current month, how many customers had 1 transaction for the previous month and the difference etc etc.  I need to represent this in a table format. 

ClaireBear_1-1572358717407.png

Thanks

 

v-shex-msft
Community Support
Community Support

HI @ClaireBear ,

Can you please share some sample data for test? It is hard to test and coding formula from your snapshot.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you so much Xiaoxin.

 

I have uploaded a pbix file with test data to OneDrive:

 

Test Data.PBIX 

 

I somehow need to link the frequency metric to the dax calculations in the same table. 

 

ClaireBear_0-1572355602978.png

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.