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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
SergioTorrinha
Resolver II
Resolver II

Active Customers if has orders in last X months

Hi all!

In my current data model, which is similar to one used my Marco Russo here , I would like to calculate te number of Actual active cusomters in a given month. I read all the content in link provided, but so far I wasn't able to find a way to build a virtual table from where it is possible to do the necessary calculations for my specific case.

This measure is to be used in a chart (x axis with a Year/Month column from dimCalendar), and needs to calculate the number of active customers in the selected month.
Active customers are the ones who ordered a product in the last 4 months of the selected Year/month.

 

Example:
1) In June 2020, the number of active customers are given by the count of customers that have at least one order done in the 4 previous months(February, March, April, May 2020).
2) In January 2020 (this is the minimal date period with data in facOrders table) Active customers will be equal to new customers (we can also apply the 4 months rule in this case, but i belive it wont be possible to propagate filters from dimCalendar to facOrders table, if at all necessary).

Can someone please recomend me a way of working this out?
I'm sorry I can't share any data as it is sensitive.
Thanks in advance. 🙂
Thanks in advance

1 ACCEPTED SOLUTION
SergioTorrinha
Resolver II
Resolver II

Hi all,

I managed to solve the issue in the meanwhile.
I'm sharing, below, the code I used in case anyone needs in future.

Actual Customers =
VAR SelParameter =
SELECTEDVALUE ( StopParameter[Stop Months] )
VAR MinDate =
MIN ( dimDates[Date] )
VAR CustomersWithOrderDate =
CALCULATETABLE (
-- Prepares a table that
SUMMARIZE (
-- for each customer contains
facOrder,
-- all their orders
facOrder[CustomerID],
facOrder[OrderDate]
),
ALLSELECTED ( dimCustomer ),
-- Regardless of local filters on customer
ALLEXCEPT (
dimDates,
dimDates[Date]
) -- and on Date
)
VAR ExistingCustomers =
FILTER (
CustomersWithNewDate,
[OrderDate]
> EOMONTH ( MinDate, - SelParameter - 1 )
&& [OrderDate] <= MinDate -- done in the last x months from current period
)
VAR Result =
COUNTROWS ( ReturningCustomers )
RETURN
Result


Thank you. 🙂

View solution in original post

2 REPLIES 2
SergioTorrinha
Resolver II
Resolver II

Hi all,

I managed to solve the issue in the meanwhile.
I'm sharing, below, the code I used in case anyone needs in future.

Actual Customers =
VAR SelParameter =
SELECTEDVALUE ( StopParameter[Stop Months] )
VAR MinDate =
MIN ( dimDates[Date] )
VAR CustomersWithOrderDate =
CALCULATETABLE (
-- Prepares a table that
SUMMARIZE (
-- for each customer contains
facOrder,
-- all their orders
facOrder[CustomerID],
facOrder[OrderDate]
),
ALLSELECTED ( dimCustomer ),
-- Regardless of local filters on customer
ALLEXCEPT (
dimDates,
dimDates[Date]
) -- and on Date
)
VAR ExistingCustomers =
FILTER (
CustomersWithNewDate,
[OrderDate]
> EOMONTH ( MinDate, - SelParameter - 1 )
&& [OrderDate] <= MinDate -- done in the last x months from current period
)
VAR Result =
COUNTROWS ( ReturningCustomers )
RETURN
Result


Thank you. 🙂

SergioTorrinha
Resolver II
Resolver II

I'm in the process of trying to insert here some sample data, but seems like HTML doesen't like me very much! 🙂
I'll let u know as soon as I can load somehting here.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.