I want to calculate the distinct count of active customers but only for the last three completed months how can I do this in DAX

0 votes

I want to calculate the distinct count of active customers but only for the last three completed months—how can I do this in DAX?
I need a DAX measure that calculates the distinct count of active customers, but it should only consider the last three fully completed months. What is the best approach using DATEADD, CALCULATE, or FILTER to ensure accurate customer count based on date filtering?

Mar 10 in Power BI by anonymous
• 25,690 points
93 views

1 answer to this question.

0 votes

To calculate the distinct count of active customers for the last three fully completed months in Power BI using DAX, follow this approach:

DAX Measure for Last 3 Completed Months' Active Customers

Active Customers (Last 3 Months) = 
VAR MaxDate = MAX( 'Date'[Date] )
VAR LastCompletedMonth = EOMONTH( MaxDate, -1 ) -- Last full month end
VAR ThreeMonthsAgo = EOMONTH( LastCompletedMonth, -2 ) -- 3 months back

RETURN 
CALCULATE( 
    DISTINCTCOUNT( 'Sales'[CustomerID] ),
    'Date'[Date] > ThreeMonthsAgo && 'Date'[Date] <= LastCompletedMonth
)

Explanation:

Discovering the Last Completed Month :

EOMONTH(MAX(Date),-1)-It gives the last day of the previous completed month.

Finding the Beginning of the 3-Month Window:

EOMONTH(LastCompletedMonth, -2)-Calculates the last day of the month that was three months ago.

Filtering the Data to the Right Range:

It uses CALCULATE() to count distinct CustomerIDs, but only within the last three completed months.

answered Mar 10 by anonymous
• 25,690 points

Related Questions In Power BI

0 votes
1 answer

How to Calculate Total Sales for the Last 3 Months Dynamically in DAX?

To dynamically calculate total sales for the ...READ MORE

answered Mar 3 in Power BI by anonymous
• 25,690 points
78 views
0 votes
1 answer

I need to show a trendline for a moving average but only for selected date ranges—how can I do this?

To do a Moving Average Trendline that ...READ MORE

answered Mar 19 in Power BI by anonymous
• 25,690 points
53 views
0 votes
1 answer
0 votes
1 answer

In DAX, how do I RETURN the sum of a calculated column from a DAX Table Variable (created via ADDCOLUMN)?

You can access column variables of previously ...READ MORE

answered Oct 8, 2020 in Power BI by Gitika
• 65,770 points
4,768 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,090 points
1,595 views
+1 vote
1 answer

Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

answered Aug 22, 2018 in Power BI by nirvana
• 3,090 points
2,934 views
+2 votes
2 answers

Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

answered Oct 11, 2018 in Power BI by Hannah
• 18,520 points
1,719 views
+1 vote
1 answer

Connect power bi desktop to dataset and create custom reports

Open power bi report nd sign in ...READ MORE

answered Oct 10, 2023 in Power BI by Monika kale

edited Mar 5 1,881 views
0 votes
1 answer

I need to calculate a running total but reset it at the start of each new quarter—how can I achieve this in DAX?

To calculate a running total that resets ...READ MORE

answered Mar 7 in Power BI by anonymous
• 25,690 points
86 views
0 votes
1 answer

I need to compute a year-over-year (YoY) growth rate but only for months where I have data in both years—how do I do this?

Calculating Year-over-Year (YoY) growth only for those ...READ MORE

answered Mar 10 in Power BI by anonymous
• 25,690 points
61 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP