Forum Discussion

locka's avatar
locka
Resolver I
1 year ago

Tickets over time

Hi everyone,

I'm trying to solve the following issue.  I need to get list of tickets open over time with multiple rows for the same ticket id.  I've been through and read many posts around this. However they only ever talk about having one entry per row. That I can count easily

I have a table which stores ticket and has a from & to dates for the days it stayes in that team.  The ticket may move between several different teams.  Before it is closed.  Also, some tickets will have a from date but yet to be completed so will have no To date.  See the table example below. or attached Pbix.  

If I had only row per REF that would be fine, but unfortunately, I can have multiple.  Also, a ticket can be closed (Have To date) and then be reopened.  Which also means it might have up to 5 days in between where it was resolved. (This can happen multiple times).  Table is updated nightly so Id never see a ticket be with two teams on the same day.  If I report over a month then a number of tickets would get counted more than once as they appear multiple times.   

I'd also like to be able break this down by team.  As well as to link this table via ID field back to a fact table so that we can look at ticket in more detail(Which I've already done.)  I Don't have a date table for the From\To (Though I do on other more import dates in other tables)

I'm assuming I need to create some virtual table of the dates chosen with those tickets which are applicable and then do a distinct count on the ref number. 

(This is not our full dataset to big to post but this is type of table we will have.  So should help)
Mock up Pbix  

Reg

From

To

Team

Closed

1

1/1/2025

3/1/2025

Team A

No

1

4/1/2025

4/1/2025

Team B

No

1

5/1/2025

8/1/2025

Team A

Yes

2

1/1/2025

2/1/2025

Central Team

Yes

3

2/1/2025

5/1/2025

Team A

No

3

6/1/2025

 

Admin Team

No

 

Thanks for looking and hopefully someone can help where I have failed

3 Replies

  • Hi locka  - you're on the right track! Since tickets can have multiple entries and may reopen.

     

    I hope you already have a date table, if not please create it using calcualted table.

    another table 

    Tickets_Expanded =
    VAR TicketDates =
    SELECTCOLUMNS (
    FILTER (
    CROSSJOIN ( 'DateTable', 'Tickets' ),
    'DateTable'[Date] >= 'Tickets'[From] &&
    ('Tickets'[To] = BLANK() || 'DateTable'[Date] <= 'Tickets'[To])
    ),
    "Date", 'DateTable'[Date],
    "TicketID", 'Tickets'[Reg],
    "Team", 'Tickets'[Team]
    )
    RETURN
    TicketDates

     

     

    create a measure to count the tickets

     

    Active Tickets =
    CALCULATE (
    DISTINCTCOUNT ( Tickets_Expanded[TicketID] ),
    CROSSFILTER ( 'DateTable'[Date], Tickets_Expanded[Date], BOTH )
    )

     

    For distinct tickets create another measure 

    Active Tickets by Team =
    CALCULATE (
    DISTINCTCOUNT ( Tickets_Expanded[TicketID] ),
    CROSSFILTER ( 'DateTable'[Date], Tickets_Expanded[Date], BOTH ),
    VALUES ( Tickets_Expanded[Team] )
    )

     

    Hope this helps.

  • Hey locka 
    Please try follwoing code , it may work

    Open Tickets =
    VAR SelectedDates =
    FILTER(
    ADDCOLUMNS(
    ALL('Tickets'),
    "IsOpen",
    'Tickets'[From] <= MAX('DateTable'[Date]) &&
    (ISBLANK('Tickets'[To]) || 'Tickets'[To] >= MIN('DateTable'[Date]))
    ),
    [IsOpen] = TRUE
    )
    RETURN
    DISTINCT(SELECTCOLUMNS(SelectedDates, "TicketID", 'Tickets'[Reg]))

    Regards
    Regards
    Govind Sapkade ( Data Analyst , Power BI PL 300 Certified , MS Fabric Enthusiast )
    Linkdin : www.linkedin.com/in/govind-sapkade-845104225
    Youtube : http://www.youtube.com/@govind_dataanalyst


  • locka's avatar
    locka
    Resolver I

    Good morning everyone.  It's been a while since my orginal post my requirments have changed a little.  Although for my inital report I was able to fix it with dax measure similar to below.  I now need to be more procises as tickets can be past between multiple people and or teams across the same peroid including same day.    I'm still looking to do a distinct count number of ticket id over a selected period. 

    This is to be used in a thin report which links to a dataset.  (They are sepreate files.)  I need this to caculate this as measure rather than a caculated table or power query etc.  I also want to make sure it can work with a drill through with list of id to allow viewer further insite.

    My main issue is there there they can be multiple entries for the same ID over the period, either on the same day or different days.  Viewer of the report can filter by a date period or the agent id or team id and bring in those tickets which match.    It's basically a tickets over time. 

    While I already have DAX code which calculates a distinct count of tickets.  When filtered by agent or team the distinct count of id and then shown it in a matrix.  The matrix is split by person which means tickets get counted more than once currently. 

    Ideally Id like to count max date time of the period per id so it would only count it once by who ever last had the ticket.  That way I can can get an accurate breakdown of how many tickets an agent or team had in period selected.  So that we can go back in the past and see how many tickets a team or agent had.

    VAR MaxDate =
        MAX ( '@DIM_Date'[Date]  ) // Newest date in the date table.
    
    VAR MinDate =
        MIN (  '@DIM_Date'[Date]  ) // Earlist date in the date table.
    
    VAR Result =
    CALCULATE(
        DISTINCTCOUNT(FACT_FaultAssignmentHistory[Faultid]),
        FACT_FaultAssignmentHistory[FromDate] <= MaxDate // Include tickets upto the end of the period.
        ,
        (
         FACT_FaultAssignmentHistory[ToDate] >= MinDate
           || ISBLANK ( FACT_FaultAssignmentHistory[ToDate] ) //Include tickets that are already open or create in the period.
        ),
        (
         FACT_Faults[ResolvedDate] >= MinDate
           || FACT_Faults[BeenResolved] = 0   //Includes those tickets which have a resolved date within period or have yet to be resolved.
        ), 
        FACT_FaultAssignmentHistory[AssignedAgentID] IN VALUES('@DIM_Agent'[AgentID]) &&
        FACT_FaultAssignmentHistory[AgentTeam] IN VALUES('@DIM_Teams'[AgentTeam])
    )
    
    RETURN
        Result

     


    Here is a sample of data below of entry every time a ticket I also have date field as well as date time ones.  This table is linked to fact table via a relationship a 1 to many.  Every time a ticket moved to another person or team.  It is recorded in the fact table below.  A separate table has list of all the tickets and other information such as has the ticket been closed or not .  I have disconnected datetable , agent and teams tables due to the fact they need to refer to multiple tables and or the same table multiple times for different reasons.  

    Table Name:   Fact_FaultsAssignmentHistory

    idAgentIDAgentTeamFromDateTimeToDateTime
    199914184208/08/2025 17:1911/08/2025 12:45
    2394021211/08/2025 10:3211/08/2025 10:59
    243191143405/08/2025 11:5011/08/2025 10:19
    243516143405/08/2025 11:5311/08/2025 10:20
    244259153224/07/2025 14:2211/08/2025 10:54
    245023174808/08/2025 16:3111/08/2025 15:20
    246629177208/08/2025 16:3811/08/2025 10:13
    247246175201/08/2025 16:3411/08/2025 07:45
    24749240206/08/2025 08:0611/08/2025 09:17
    247937186230/07/2025 08:1611/08/2025 09:22
    2491691211/08/2025 10:5411/08/2025 14:10
    24916922106/08/2025 15:1311/08/2025 10:54
    24927338608/08/2025 09:4011/08/2025 08:16
    249744162204/08/2025 09:0911/08/2025 12:10
    250200162204/08/2025 10:5211/08/2025 09:30
    2503821211/08/2025 12:0611/08/2025 12:33
    250382161204/08/2025 13:5011/08/2025 12:06
    2503831105/08/2025 16:0611/08/2025 16:10
    2505021211/08/2025 12:4011/08/2025 13:03
    250502154204/08/2025 16:1311/08/2025 12:40
    250521125208/08/2025 15:0111/08/2025 10:03
    25059740206/08/2025 08:0611/08/2025 09:21
    25087240206/08/2025 08:0611/08/2025 09:18
    250909161205/08/2025 11:3311/08/2025 13:55
    2509641210/08/2025 06:5611/08/2025 08:53
    251230132205/08/2025 16:4211/08/2025 08:49
    2512741411/08/2025 16:4311/08/2025 16:50
    25134240206/08/2025 10:2111/08/2025 09:20
    251361124307/08/2025 09:4811/08/2025 08:44
    2514891311/08/2025 11:4511/08/2025 12:22
    251489127311/08/2025 12:2211/08/2025 12:28
    25158940206/08/2025 11:5411/08/2025 09:19