Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I have a star schema, and I need to calculate the cumulative number of active customers each month. A customer can be counted multiple times if they were active in different months. An active customer is one who made a transaction and has a row in the transactions table.
The calculation should cover the last 12 months, with the first month starting in October 2023 (from the 1st to the 7th), and the last month being the current one, up to the latest day.
The cumulative count should sum the active customers month by month.
I need help with Dax formula to achieve it.
PBIX is attached
Solved! Go to Solution.
Hi,
Thank you for your message.
Sorry that I don't understand 100%, but, if the condition is to specify the starting period based on the needs, please try something like below.
In the measure, regarding VAR _startingdate, I hope you can try to fix it based on the needs.
expected result measure: =
VAR _startdate =
DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), 1 ) //custom start date
VAR _startdatecode =
MAXX (
FILTER (
ALL ( 'Calendar'[Date], 'Calendar'[Year-Month Code] ),
'Calendar'[Date] = _startdate
),
'Calendar'[Year-Month Code]
) //custom yearmonth code
VAR _t =
FILTER (
WINDOW (
1,
ABS,
0,
REL,
ALL ( 'Calendar'[Year-Month], 'Calendar'[Year-Month Code] ),
ORDERBY ( 'Calendar'[Year-Month Code], ASC )
),
'Calendar'[Year-Month Code] >= _startdatecode
)
VAR _bydefinition =
ADDCOLUMNS (
_t,
"@distinctcount", CALCULATE ( COUNTROWS ( DISTINCT ( 'orders'[Customer ID] ) ) )
)
RETURN
SUMX ( _bydefinition, [@distinctcount] )
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.
RT_12M =
VAR __lymtd =
CALCULATE(
[Customers quantity],
CALCULATETABLE(
DATEADD( DATESMTD( 'Calendar'[Date] ), -1, YEAR ),
KEEPFILTERS( 'Calendar'[Date] <= TODAY() )
)
)
VAR __11m =
CALCULATE(
SUMX( VALUES( 'Calendar'[Year-Month] ), [Customers quantity] ),
DATESINPERIOD( 'Calendar'[Date], MIN( 'Calendar'[Date] ) - 1, -11, MONTH )
)
RETURN
__lymtd + __11m
RT_12M =
VAR __lymtd =
CALCULATE(
[Customers quantity],
CALCULATETABLE(
DATEADD( DATESMTD( 'Calendar'[Date] ), -1, YEAR ),
KEEPFILTERS( 'Calendar'[Date] <= TODAY() )
)
)
VAR __11m =
CALCULATE(
SUMX( VALUES( 'Calendar'[Year-Month] ), [Customers quantity] ),
DATESINPERIOD( 'Calendar'[Date], MIN( 'Calendar'[Date] ) - 1, -11, MONTH )
)
RETURN
__lymtd + __11m
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LeanAndPractise(Everyday) ) |
Hi @ThxAlot
Thank you very much for your response. I'm not referring to a rolling 12-month sum, but rather a cumulative count month by month for a 12-month period. Please see my reply to @Jihwan_Kim
Hi,
I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.
WINDOW function (DAX) - DAX | Microsoft Learn
expected result measure: =
VAR _t =
WINDOW (
1,
ABS,
0,
REL,
ALL ( 'Calendar'[Year-Month], 'Calendar'[Year-Month Code] ),
ORDERBY ( 'Calendar'[Year-Month Code], ASC )
)
VAR _bydefinition =
ADDCOLUMNS (
_t,
"@distinctcount", CALCULATE ( COUNTROWS ( DISTINCT ( 'orders'[Customer ID] ) ) )
)
RETURN
SUMX ( _bydefinition, [@distinctcount] )
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.
Hi @Jihwan_Kim
Thank you very much, for the help. You got it right, except I need it for the last 13 months, not from the start of the calender. Meaning, October 2023 should be 0, and the accumulation should start from there. Your calculation sums correctly, but I can't manage to limit the period.
screenshot from my original file :
I have a dax for standard distinct count like :
Hi,
Thank you for your message.
Sorry that I don't understand 100%, but, if the condition is to specify the starting period based on the needs, please try something like below.
In the measure, regarding VAR _startingdate, I hope you can try to fix it based on the needs.
expected result measure: =
VAR _startdate =
DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), 1 ) //custom start date
VAR _startdatecode =
MAXX (
FILTER (
ALL ( 'Calendar'[Date], 'Calendar'[Year-Month Code] ),
'Calendar'[Date] = _startdate
),
'Calendar'[Year-Month Code]
) //custom yearmonth code
VAR _t =
FILTER (
WINDOW (
1,
ABS,
0,
REL,
ALL ( 'Calendar'[Year-Month], 'Calendar'[Year-Month Code] ),
ORDERBY ( 'Calendar'[Year-Month Code], ASC )
),
'Calendar'[Year-Month Code] >= _startdatecode
)
VAR _bydefinition =
ADDCOLUMNS (
_t,
"@distinctcount", CALCULATE ( COUNTROWS ( DISTINCT ( 'orders'[Customer ID] ) ) )
)
RETURN
SUMX ( _bydefinition, [@distinctcount] )
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
99 | |
69 | |
46 | |
39 | |
33 |
User | Count |
---|---|
163 | |
110 | |
61 | |
51 | |
40 |