Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I would like to build table that counts the number of records between to dates.
I have data below call Data and date table called Calendar. My Data table looks like this.
I have date table has one column with all the dates from my data colunm.
When I use the following measure, I return only the date that are equal to the start date. When there is a relationship between Data[Start Date] and Calendar'[Date]. We I remove the relationship it works as expected. My question is why?
OpenItems =
VAR DateX = MAX('Calendar'[Date])
Return
CALCULATE(COUNTROWS(Data),Data[Start Date]<=DateX)
OpenItems =
VAR DateX = MAX('Calendar'[Date])
Return
CALCULATE(COUNTROWS(Data),Data[Start Date]<=DateX && Data[End Date]>Datex)
Solved! Go to Solution.
Hi @leekohr ,
The behavior you're observing is likely due to the way DAX handles filter context in Power BI. When there is an active relationship between the Data table and the Calendar table, the filter context is automatically applied based on that relationship. This means that when you calculate the measure, it is only considering the dates that match exactly in both tables due to the relationship.
Here's a step-by-step action plan to resolve the issue:
1. Review Relationships:
- Ensure that the relationship between the Data table and the Calendar table is set up correctly. It should typically be a one-to-many relationship, with the Calendar table on the "one" side.
2. Modify the Measure:
- You may need to adjust your measure to ignore the filter context imposed by the relationship. You can do this by using the ALL() function or to REMOVEFILTERS() function the filter context from the Calendar table.
OpenItems =
VAR DateX = MAX('Calendar'[Date])
Return
COUNTROWS(FILTER(ALL(Data),Data[Start Date]<=DateX && Data[End Date]>Datex))
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @leekohr ,
The behavior you're observing is likely due to the way DAX handles filter context in Power BI. When there is an active relationship between the Data table and the Calendar table, the filter context is automatically applied based on that relationship. This means that when you calculate the measure, it is only considering the dates that match exactly in both tables due to the relationship.
Here's a step-by-step action plan to resolve the issue:
1. Review Relationships:
- Ensure that the relationship between the Data table and the Calendar table is set up correctly. It should typically be a one-to-many relationship, with the Calendar table on the "one" side.
2. Modify the Measure:
- You may need to adjust your measure to ignore the filter context imposed by the relationship. You can do this by using the ALL() function or to REMOVEFILTERS() function the filter context from the Calendar table.
OpenItems =
VAR DateX = MAX('Calendar'[Date])
Return
COUNTROWS(FILTER(ALL(Data),Data[Start Date]<=DateX && Data[End Date]>Datex))
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
how is your measure visualized or what filter context do you have?
it could be that you are using the calendar[date] to get a date range and a date point in the same time, so only the the date point meets such requirement.
I add the date field to the X-Axis and the measure to Y-axis to create the following chart.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
10 | |
10 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |