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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
andi2333
Helper I
Helper I

Distinct calculation of dates within a range

Hello, I require support on the following issue (quite new to PBI, hence not entirely sure if there is a simple solution to this).

 

I have a table which essentially carries ticket IDs, some ticket metadata (e.g. severity, accountable team), and two date fields: (ticket_opened) and (ticket_closed). The latter one could of course be empty in case the ticket has not been solved yet.

 

I know want to create a line chart showing the active tickets per calendar week. My problem is two-fold:

1. Date Hierarchy in PowerBi does not seem to include calendar weeks? - is there a trick to get this view?

2. I dont know how to distincly calculate the respective rows. 

Example: my table has the following entries:

                  opened              closed

INC0001    01.01.2023         05.01.2023

INC0002   01.01.2023          03.01.2023

INC0003    02.01.2023          04.01.2023

 

This means I had three open tickets in calendar week 1. However, if I do a sum of countrows, I get a much higer count as it counts each day and then sums up the value for the week.

 

Any support is much appreciated. Thank you.

 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @andi2333,

 

To point 1: You'll need to set up a proper calendar table (I'd recommend in Power Query) and set it up with whichever date dimension you want to use. There's loads of tutorials online how to do this, so I'll no go into any further depth here.

 

Point 2: Once you've got your calendar table, you can create a measure like this to get open tickets at the end of any given date dimension period:

_openTicketsOverTime =
VAR __cDate = MAX(calendar[date])
RETURN
CALCULATE(
    DISTINCTCOUNT(yourTable[TicketID]),
    FILTER(
        yourTable,
        yourTable[opened] <= __cDate
        && ( yourTable[closed] > __cDate || ISBLANK(yourTable[closed]) )
    )
)

 

Just make sure to use the period dimension from your calendar table on the chart axis.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
BA_Pete
Super User
Super User

Hi @andi2333,

 

To point 1: You'll need to set up a proper calendar table (I'd recommend in Power Query) and set it up with whichever date dimension you want to use. There's loads of tutorials online how to do this, so I'll no go into any further depth here.

 

Point 2: Once you've got your calendar table, you can create a measure like this to get open tickets at the end of any given date dimension period:

_openTicketsOverTime =
VAR __cDate = MAX(calendar[date])
RETURN
CALCULATE(
    DISTINCTCOUNT(yourTable[TicketID]),
    FILTER(
        yourTable,
        yourTable[opened] <= __cDate
        && ( yourTable[closed] > __cDate || ISBLANK(yourTable[closed]) )
    )
)

 

Just make sure to use the period dimension from your calendar table on the chart axis.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.