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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Calculate ammount of open tickets in a given date

Hello,

 

I've been trying for some time to find a way to calculate the amount of open tickets on an arbitrary date, so that I can create a graph of the number of tickets through time. But despite testing different solutions, it hasn't worked so far.

 

I have two tables:

  1. One is a database which contains the date in which tickets are opened, when (or if) they were closed and its current status.
  2. The other one is simply a "calendar" that has all the days between 01/01/2010 and today.

My objective is to, for a respective date X in the calendar, count how many tickets were opened at that point in time (so every one whose date opened is <=X and date closed is >X or blank).

 

Their relationship is as follows:

T_Reis_2-1666268754212.png

 

Here is a minimal working example of the database:

Date OpenedDate ClosedCurrent Status
11/04/201711/05/2018Closed
15/02/2018 Open
24/11/201816/11/2021Closed
04/02/2019 Open
27/07/2019 Open
24/09/201929/10/2020Closed
12/08/2021 Open

 

So given these values, the number of tickets would be (filler dates removed):

Day Number of open tickets
10/04/2017 0
12/04/2017 1
15/02/2018 2
12/05/2018 1
04/02/2019 3
27/07/2019 4
29/09/2019 5
30/10/2020 4
12/08/2021 5
19/10/2022 4

 

Browsing the forums, I've come across this formula, although it didn't seem to work:

 

Count = 
CALCULATE(
    COUNT('Database'[Status]),
    Database[Date Opened] <= MIN(Calendar[Day]) &&
    Database[Date Closed] >= MAX(Calendar[Day])
)

 

 

Any assistance would be appreciated.

 

PS.: Here is the graph working on Excel using the formula

 

=COUNTIFS(Database[Date Opened];"<="&A2;Database[Date Closed];">"&A2) +
COUNTIFS(Database[Date Opened];"<="&A2;Database[Date Closed];"")

 

with A2 being a date.

T_Reis_0-1666265220810.png

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here I suggest you to try this code to create a measure to count status.

Count = 
CALCULATE (
    COUNT ( ' Database'[Current Status] ),
    FILTER (
        ' Database',
        ' Database'[Date Opened] <= MAX ( 'Calendar'[Date] )
            && OR (
                ' Database'[Date Closed] > MAX ( 'Calendar'[Date] ),
                ' Database'[Date Closed] = BLANK ()
            )
    )
) + 0

My Sample:

RicoZhou_0-1666339256992.png

Calendar = CALENDAR(DATE(2017,01,01),DATE(2022,12,31))

Result is as below.

RicoZhou_1-1666339300945.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous ,

 

Here I suggest you to try this code to create a measure to count status.

Count = 
CALCULATE (
    COUNT ( ' Database'[Current Status] ),
    FILTER (
        ' Database',
        ' Database'[Date Opened] <= MAX ( 'Calendar'[Date] )
            && OR (
                ' Database'[Date Closed] > MAX ( 'Calendar'[Date] ),
                ' Database'[Date Closed] = BLANK ()
            )
    )
) + 0

My Sample:

RicoZhou_0-1666339256992.png

Calendar = CALENDAR(DATE(2017,01,01),DATE(2022,12,31))

Result is as below.

RicoZhou_1-1666339300945.png

 

Best Regards,
Rico Zhou

 

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

Anonymous
Not applicable

Hey @v-rzhou-msft, my apologies for the delay in responding.

 

Thank you so much for the help! Although the code didn't do a cumulative sum initially (it was only displaying the amount of tickets for a given day), adding ALLSELECTED()  to the first FILTER parameter seems to have made it work.

 

Count = 
CALCULATE (
    COUNT ( ' Database'[Current Status] ),
    FILTER (
        ALLSELECTED(' Database'),
        ' Database'[Date Opened] <= MAX ( 'Calendar'[Date] )
            && OR (
                ' Database'[Date Closed] > MAX ( 'Calendar'[Date] ),
                ' Database'[Date Closed] = BLANK ()
            )
    )
) + 0

 

T_Reis_0-1673275091307.png

 

Again, thanks for the assistance in this matter.

 

 

Best regards,

Tiago Reis

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.