Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
FVZ
Frequent Visitor

Counting objects over time with startDate & endDate

Hi Community,

 

I would like to get some inspiration/help to create a DAX measure. For my report, I need to display the count of statusses over time, using a start and enddate. Ideally, this should be dynamic. So that it works with both days, weeks and months on the axes.

 

This is what the data looks like (text and picture format):

 

statusstartDateendDate
XXX1-1-202429-2-2024
YYY1-2-202415-2-2024
BBB1-1-202430-4-2024
XXX1-1-202431-3-2024

 

FVZ_0-1726471544693.png

 

And this is how it should be visualized (example with months, but should work with days & weeks too):

FVZ_0-1726471284126.png

 

I have difficulty with creating something like this, so it would be great if some of you could help out! If you have any idea, please provide the DAX!

 

Kind regards

2 ACCEPTED SOLUTIONS
sanalytics
Super User
Super User

@FVZ 

If I understand your problem correctly, you want to count the number of ongoing statuses between a given start date and end date.

For example:

For status XXX, one started on 1st Jan 2024 and ended on 29th Feb 2024, and another started on 1st Jan 2024 and ended on 31st March 2024.

In January, the count should be 2 since both started in this month.

In February, the count should still be 2 because the first one ends in February, and the second one, which ends in March, is still ongoing.

In March, the count would be 1 as only the second status is ongoing.

For status BBB, starting in January 2024 and ending in April, the count for February, March, and April will be 1 each month, as it continues through all those months.

The same logic applies to weekly calculations.

If this understanding is correct, here’s my suggested solution:

  1. Prepare your data: Go to Power Query and generate a list of rows for each status between the start and end dates.
  2. Create a Date table: You can create this in either Power Query or using DAX.
  3. Write a small DAX.

The complete solution is in the link below.

https://we.tl/t-t7VUBbwner

below screenshot

sanalytics_0-1726494400485.png

 

While I could solve this using DAX, but I always follow Roche's Maxim rule "Data should be transformed as far upstream as possible, and as far downstream as necessary."

If you need a DAX-only solution, please allow me some time to provide it. I must mention that it’s not an easy task.

 

Hope this helps!

Regards

sanalytics

If it is your solution then please like and accept it as solution

 

View solution in original post

Anonymous
Not applicable

Hi @FVZ 

 

Thank you very much sanalytics、Selva-Salimi and bhanu_gautam for your prompt reply.

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"StatusTable"

vnuocmsft_0-1726558548348.png

 

Create a Date Table.

 

DateTable = 
ADDCOLUMNS (
    CALENDAR (MIN('StatusTable'[startDate]), MAX('StatusTable'[endDate])),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "MMM"),
    "Week", WEEKNUM([Date]),
    "Day", DAY([Date])
)

 

Create a mesure.

 

StatusCount = 
VAR max_d = MAX('DateTable'[Date])
var min_d = MIN('DateTable'[Date])
VAR CountStatuses = 
    CALCULATE (
        COUNTROWS('StatusTable'),
        FILTER (
            'StatusTable',
            'StatusTable'[startDate] <= max_d &&
            'StatusTable'[endDate] >= min_d
        )
    )
RETURN
IF(ISBLANK(CountStatuses), 0, CountStatuses)

 

Create a Line chart visual.

 

vnuocmsft_1-1726558900823.png

 

Here is the result.

 

vnuocmsft_2-1726558943356.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @FVZ 

 

Thank you very much sanalytics、Selva-Salimi and bhanu_gautam for your prompt reply.

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"StatusTable"

vnuocmsft_0-1726558548348.png

 

Create a Date Table.

 

DateTable = 
ADDCOLUMNS (
    CALENDAR (MIN('StatusTable'[startDate]), MAX('StatusTable'[endDate])),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "MMM"),
    "Week", WEEKNUM([Date]),
    "Day", DAY([Date])
)

 

Create a mesure.

 

StatusCount = 
VAR max_d = MAX('DateTable'[Date])
var min_d = MIN('DateTable'[Date])
VAR CountStatuses = 
    CALCULATE (
        COUNTROWS('StatusTable'),
        FILTER (
            'StatusTable',
            'StatusTable'[startDate] <= max_d &&
            'StatusTable'[endDate] >= min_d
        )
    )
RETURN
IF(ISBLANK(CountStatuses), 0, CountStatuses)

 

Create a Line chart visual.

 

vnuocmsft_1-1726558900823.png

 

Here is the result.

 

vnuocmsft_2-1726558943356.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

sanalytics
Super User
Super User

@FVZ 

If I understand your problem correctly, you want to count the number of ongoing statuses between a given start date and end date.

For example:

For status XXX, one started on 1st Jan 2024 and ended on 29th Feb 2024, and another started on 1st Jan 2024 and ended on 31st March 2024.

In January, the count should be 2 since both started in this month.

In February, the count should still be 2 because the first one ends in February, and the second one, which ends in March, is still ongoing.

In March, the count would be 1 as only the second status is ongoing.

For status BBB, starting in January 2024 and ending in April, the count for February, March, and April will be 1 each month, as it continues through all those months.

The same logic applies to weekly calculations.

If this understanding is correct, here’s my suggested solution:

  1. Prepare your data: Go to Power Query and generate a list of rows for each status between the start and end dates.
  2. Create a Date table: You can create this in either Power Query or using DAX.
  3. Write a small DAX.

The complete solution is in the link below.

https://we.tl/t-t7VUBbwner

below screenshot

sanalytics_0-1726494400485.png

 

While I could solve this using DAX, but I always follow Roche's Maxim rule "Data should be transformed as far upstream as possible, and as far downstream as necessary."

If you need a DAX-only solution, please allow me some time to provide it. I must mention that it’s not an easy task.

 

Hope this helps!

Regards

sanalytics

If it is your solution then please like and accept it as solution

 

Selva-Salimi
Super User
Super User

Hi @FVZ 

 

you can write a measure as follows:

CountStatusesOverTime =
VAR SelectedDate = SELECTEDVALUE('DimDate '[Dates])
 var statusCount = CALCULATE(COUNT(Tbl[Status]) , FILTER((Tbl) , Tbl[StartDate]<= SelectedDate && Tbl[EndDate] >= SelectedDate) )
RETURN
statusCount+0
 
** you should not have relation between dimdate and tbl and use dates of DimDate in X-axis
 
If this post helps, then I would appreciate a thumbs up  and mark it as the solution to help the other members find it more quickly. 
bhanu_gautam
Super User
Super User

@FVZ ,Create a Date table if you don't already have one. This table should include all the dates you want to analyze.

 

Create a measure to count the statuses over time

Status Count =
VAR SelectedDate = MAX('Date'[Date])
RETURN
CALCULATE(
COUNTROWS('YourTable'),
FILTER(
'YourTable',
'YourTable'[startDate] <= SelectedDate &&
'YourTable'[endDate] >= SelectedDate
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Unfortunately I can't get it to work. These are the results I get: 

FVZ_1-1726480835535.png

 

I also wondered if I shouldn't do something with the relationship between the endDate and Date from my datetable? Right now I only have a relationship between startDate and Date: 

FVZ_0-1726480762325.png

I suppose the measure also needs to be adjusted when I create two relationships. 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.