Excel Power Pivot: Count Customers in the Latest Month Without Filters
Question details
Create a Power Pivot measure that counts distinct customers in the latest available month without unwanted source-table filters.

- Product
- Microsoft Excel Power Pivot
- Device & OS
- not provided
- Scenario
- A PivotTable uses a calendar table and a customer source table, but the latest-month count should ignore filters that would otherwise change the result.
- Observed behavior
- The distinct customer count can change when filters on the source table affect the measure.
Identify the calendar date column, source-table date column, and customer ID column in the Data Model. Confirm that the calendar is related to the source table and that its latest date represents the month you want to count.
Create a DAX measure that clears filters and selects the latest calendar month
Use this approach when the calendar table ends in the latest month to report and you want to ignore source-table and calendar filters.
The example assumes an active relationship from 'Calendar'[Date] to 'Sales'[Date], with the calendar filtering the Sales table. Replace the table and column names with those in your model.
The latest month comes from the calendar, not necessarily the latest transaction. If the calendar includes future months, restrict it to the intended reporting range or change the latest-date calculation to match your business rule.
Open Power Pivot > Manage, then use Diagram View to confirm that 'Calendar'[Date] has an active relationship to 'Sales'[Date].
In Excel, open Power Pivot > Measures > New Measure. Select the appropriate table, name the measure Latest Month Customers, and enter this formula in the formula box: =VAR LatestDate = CALCULATE(MAX('Calendar'[Date]), ALL('Calendar'), ALL('Sales')) VAR MonthStart = DATE(YEAR(LatestDate), MONTH(LatestDate), 1) VAR MonthEnd = EOMONTH(LatestDate, 0) RETURN IF( ISBLANK(LatestDate), BLANK(), CALCULATE( DISTINCTCOUNT('Sales'[CustomerID]), ALL('Sales'), FILTER(ALL('Calendar'), 'Calendar'[Date] >= MonthStart && 'Calendar'[Date] <= MonthEnd) ) )
Add Latest Month Customers to the PivotTable Values area. Compare it with a manual distinct count for the same month, then change source-table and date filters to check that the result remains as intended.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move everyday workbook tasks between applications. It does not fix Microsoft Power Pivot or guarantee compatibility with Power Pivot data models and DAX measures.

Frequently Asked Questions
Why does my latest-month customer count change with slicers?
Slicers add filter context to the PivotTable. In the measure, use ALL or REMOVEFILTERS inside CALCULATE to clear the filters you do not want, then apply the intended month filter.
What if my calendar table contains future dates?
MAX('Calendar'[Date]) may select a future month with no sales. Adjust the calendar's reporting range or calculate the latest date according to your business rule, such as the latest transaction date.
Does DISTINCTCOUNT count blank customer IDs?
Yes. DISTINCTCOUNT treats a blank as a distinct value. If blanks are invalid customer IDs, add an appropriate nonblank filter to the measure and test the result.
Why does the measure show a different result from my manual count?
Check the active relationship in Power Pivot > Manage > Diagram View, confirm the latest calendar month, and compare the customer IDs included in that month. Also check filters from related tables and whether blank IDs are counted.




