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
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
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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