How to Correct a DAX Measure for Open Doors on the Latest Date
Question details
The user needs to correct a DAX measure that improperly counts open doors by filtering for open records before finding the latest date, resulting in inaccurate metrics when the true latest record is closed.

- Product
- Spreadsheets
- Device & OS
- not provided
- Scenario
- Calculating the total number of open doors based specifically on the absolute latest recorded date for a given site.
- Observed behavior
- The existing measure returns an open door even when the most recent record is closed, because it evaluates the latest date only among records that already have an 'Open' status.
Ensure that the primary key and foreign key columns used in your relationships (such as SiteId and SiteCode) share the exact same data type to prevent calculation errors.
Update the DAX Measure Using Variables to Determine the Date First
Use DAX variables to first isolate the absolute maximum date in the current filter context, then apply that date as a filter to count the open records.
By separating the logic into variables, you prevent the measure from pre-filtering the dataset. The variable evaluates the overall latest date for the site, regardless of status. The return statement then checks if the status on that specific date is 'Open'.
Open your data model's formula bar and create a new measure. Start by defining a variable that calculates the overall maximum date: VAR LatestDate = CALCULATE(MAX(BMSDoorStoreJoin[CreatedOn])).
Add the RETURN statement to calculate the rows matching both the latest date and the open status: RETURN CALCULATE(COUNTROWS(BMSDoorStoreJoin), BMSDoorStoreJoin[Status] = "Open", BMSDoorStoreJoin[CreatedOn] = LatestDate).
If your KPI visual requires a blank instead of a zero when the latest record is closed, wrap the entire expression in an IF function: IF([Doors Open] = 0, BLANK(), [Doors Open]).
Navigate to the Model View and ensure that the fields connecting your tables (e.g., SiteId as a whole number and SiteCode as text) are cast to identical data types.
Analyze Your Data with WPS Spreadsheets
While DAX measures are specific to Microsoft's data modeling tools, WPS Office provides a lightweight, free alternative for comprehensive data analysis. With advanced PivotTables, powerful built-in formulas, and a highly intuitive interface, WPS Spreadsheets easily handles your daily reporting needs.
- 1. Download and Install WPS Office: Visit the official WPS Office website and download the free installation package for your operating system.
- 2. Open your data file: Launch WPS Spreadsheets and open your existing .xlsx or .csv data files with full compatibility.
- 3. Utilize advanced formulas and PivotTables: Analyze your data using standard formulas like MAXIFS and COUNTIFS, or summarize your records instantly using PivotTables.

Frequently Asked Questions
Why does my DAX measure return an open status for closed records?
This happens when the measure applies the 'Open' filter before determining the maximum date. It finds the latest date among the open records only, ignoring more recent records that are closed.
How do I make a DAX measure return BLANK instead of zero?
You can wrap your main calculation in an IF statement. For example, IF([Your Measure] = 0, BLANK(), [Your Measure]). This forces the visual to display an empty space instead of a zero.
Why am I getting relationship errors in my data model?
Relationship errors frequently occur when the primary and foreign keys used to link tables have different data types (e.g., linking a whole number SiteId to a text SiteCode). You must convert them to the same data type in your data query.




