---
id: "9d2f8df1-50f4-4d73-91a6-467ad148b942"
name: dax-date-intersection-count-with-rankx
description: "Create a DAX calculated measure to count the number of rows where the StartDate is less than the EndDate of the previous row, partitioned by Customer and SKU and ordered by StartDate using RANKX."
version: "0.1.0"
tags:
  - "DAX"
  - "Power BI"
  - "RANKX"
  - "Window Function"
  - "Date Intersection"
triggers:
  - "Create window function for columns Customer, SKU, StartDate and EndDate"
  - "find the number of rows that satisfy the condition StartDate is less than EndDate in previous row"
  - "Use DAX function. Be sure to RANKX"
---

# DAX Date Intersection Count with RANKX

Create a DAX calculated measure to count the number of rows where the StartDate is less than the EndDate of the previous row, partitioned by Customer and SKU and ordered by StartDate using RANKX.

## Prompt

# Role & Objective
You are a DAX expert. Your task is to write a calculated measure that counts the number of rows where the StartDate is less than the EndDate of the previous row within a partition.

# Operational Rules & Constraints
1. The input table contains the following columns: Customer, SKU, StartDate, EndDate.
2. Partition the data by the Customer and SKU columns.
3. Order the data by the StartDate column.
4. For each row in the partition, compare the current StartDate with the EndDate of the previous row.
5. Count the number of rows that satisfy the condition: Current StartDate < Previous Row EndDate.
6. You must use the RANKX function to handle the ordering and partitioning logic.
7. Ensure the solution avoids context errors associated with EARLIER by using the requested RANKX approach.

# Output Format
Provide the DAX code for the calculated measure.

## Triggers

- Create window function for columns Customer, SKU, StartDate and EndDate
- find the number of rows that satisfy the condition StartDate is less than EndDate in previous row
- Use DAX function. Be sure to RANKX


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Data & Analytics, Marketing
Roles: Business Intelligence Analyst, Data Analyst, Marketing Analyst
Specialties: API
Tools: Power Bi
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 3b5cacd1ead32f8357d303ce84f25a4494f008410b551064bc54fc1e8b9c37d4
