The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi,
I'm seeking help to get the count of customers who have placed orders at least once every month for the past X months.
For example, I am hoping to capture the count of customers who have orders in October, November and December (past 2 months and current month).
Any help and guidance is much appreciated.
Thanks,
Ashley
Solved! Go to Solution.
Hi! Here's some DAX for something similar I did...
VAR Weeks = 2
VAR CurrentWeek =
CALCULATETABLE (
VALUES ( IdentityLog[IdentityId] ),
DATESINPERIOD (
'Calendar'[Date],
DATEADD (
LASTDATE ( 'Calendar'[Date] ),
( Weeks * 7 ) + 1,
DAY
),
7,
DAY
)
)
VAR PreviousWeek =
CALCULATETABLE (
VALUES ( IdentityLog[IdentityId] ),
DATESINPERIOD (
'Calendar'[Date],
DATEADD (
LASTDATE ( 'Calendar'[Date] ),
( ( Weeks - 1 ) * 7 ) + 1,
DAY
),
7,
DAY
)
)
VAR TwoWeeksAgo =
CALCULATETABLE (
VALUES ( IdentityLog[IdentityId] ),
DATESINPERIOD (
'Calendar'[Date],
DATEADD (
LASTDATE ( 'Calendar'[Date] ),
( ( Weeks - 2 ) * 7 ) + 1,
DAY
),
7,
DAY
)
)
RETURN
COUNTROWS (
CALCULATETABLE (
VALUES(IdentityLog[IdentityId]),
CurrentWeek,
PreviousWeek,
TwoWeeksAgo
)
)
The measure above is intended to get the count of users who have logged in each week for three consecutive weeks. Replace my logic for weeks with current month, prior month and two months ago (PARALLELPERIOD() should make that very easy!).
hey this would do the trick (a measure):
if this was of help for your need let us know makring as soluction.
Proud to be a Super User!
@aiweller , This measure can give distinct month has sales , with help from date table
Example
Rolling 3 = CALCULATE(distinctcount('Date'[Month-Year]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date ]),0),-3,MONTH), not(isblank(Sales[Sales Amount])))
Count of customers having entry in three month
new Measure = countx(filter(Summarize(Sales, sales[Customer], "_1",[Rolling 3]),[_1]=3),[Customer])
Thank you all for the solutions. I spent the last 2 weeks trying to find a solution myself on google search and got a solution within 1 day in this community. :). You guys are great!
@aiweller , This measure can give distinct month has sales , with help from date table
Example
Rolling 3 = CALCULATE(distinctcount('Date'[Month-Year]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date ]),0),-3,MONTH), not(isblank(Sales[Sales Amount])))
Count of customers having entry in three month
new Measure = countx(filter(Summarize(Sales, sales[Customer], "_1",[Rolling 3]),[_1]=3),[Customer])
hey this would do the trick (a measure):
if this was of help for your need let us know makring as soluction.
Proud to be a Super User!
Hi! Here's some DAX for something similar I did...
VAR Weeks = 2
VAR CurrentWeek =
CALCULATETABLE (
VALUES ( IdentityLog[IdentityId] ),
DATESINPERIOD (
'Calendar'[Date],
DATEADD (
LASTDATE ( 'Calendar'[Date] ),
( Weeks * 7 ) + 1,
DAY
),
7,
DAY
)
)
VAR PreviousWeek =
CALCULATETABLE (
VALUES ( IdentityLog[IdentityId] ),
DATESINPERIOD (
'Calendar'[Date],
DATEADD (
LASTDATE ( 'Calendar'[Date] ),
( ( Weeks - 1 ) * 7 ) + 1,
DAY
),
7,
DAY
)
)
VAR TwoWeeksAgo =
CALCULATETABLE (
VALUES ( IdentityLog[IdentityId] ),
DATESINPERIOD (
'Calendar'[Date],
DATEADD (
LASTDATE ( 'Calendar'[Date] ),
( ( Weeks - 2 ) * 7 ) + 1,
DAY
),
7,
DAY
)
)
RETURN
COUNTROWS (
CALCULATETABLE (
VALUES(IdentityLog[IdentityId]),
CurrentWeek,
PreviousWeek,
TwoWeeksAgo
)
)
The measure above is intended to get the count of users who have logged in each week for three consecutive weeks. Replace my logic for weeks with current month, prior month and two months ago (PARALLELPERIOD() should make that very easy!).
User | Count |
---|---|
16 | |
8 | |
7 | |
6 | |
6 |
User | Count |
---|---|
26 | |
13 | |
12 | |
8 | |
8 |