Forum Discussion
Measure for a total count by month
- 1 year ago
Hey there!
You'll need a DAX measure or query that counts the dogs who have overlapping dates within each month of 2024.
You can create a measure like:
ActiveDogs =
COUNTROWS(
FILTER(
Dogs,
(Dogs[Start_Date] <= MAX(Calendar[Date]) && Dogs[End_Date] >= MIN(Calendar[Date]))
)
)This counts the number of dogs whose start and end dates overlap with the selected month.
for you second question:
If you have a Start_Date and End_Date field and you're using a Calendar table, applying a Year and Month filter might not yield correct results. A common solution is to use a DAX measure that explicitly checks if the date range is between the Start_Date and End_Date.
Here’s an approach to work with the date filter correctly:
ActiveDogsPerMonth =
CALCULATE(
[ActiveDogs],
FILTER(
Calendar,
Calendar[Date] >= MIN(Dogs[Start_Date]) &&
Calendar[Date] <= MAX(Dogs[End_Date])
)
)Hope this helps!
😁😁
Hi freginier thanks so much for your explanation and help so far. I feel like the deeper I go, the more issues pop up. I can connect the Start_Date or End_Date individually Many to One, but when I try to add the 2nd it says:
Any ideas how to fix this? Thanks for all of your help so far!
Hi RichOB,
Power BI detects multiple paths between the 'Dogs' table and the 'Calendar' table that creates an ambiguous relationship. This happens because you're trying to connect both Start_Date and End_Date from 'Dogs' to 'Calendar'.
To resolve your issue: Keep one relationship active and Create the second relationship as inactive.
Regards,
Vinay Pabbu