Forum Discussion

RichOB's avatar
RichOB
Icon for Post Partisan rankPost Partisan
1 year ago
Solved

Measure for a total count by month

Hi, I'm looking to get the count of total dogs who were actively in a kennel each month in 2024. Using the table, what measure would give me the figures below, please? Also, I need to add a year and ...
  • freginier's avatar
    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!

    ๐Ÿ˜๐Ÿ˜