Forum Discussion

Thogen's avatar
Thogen
Frequent Visitor
2 years ago
Solved

Open Incidents per day

Dear All,

I'm having some trouble with creating a measure which check for the number of open incidents.
I want to place this measure in a matrix or chart with Date on the rows.

  1. My thought process has been the following:
    I have a fact table called Raw_Transaction which contains status changes for incidents such as creating, updating, and closing. An IncidentId can appear multiple times in this table, and an incident ID can be opened and closed multiple times. So an incident ID will have multiple records. This table is ~15.000.000 rows. 
  2. To make it a bit easier for myself (I think...), I've created a column which is a basically a RANK number of what number this transaction is for an incidentID, called "CountOfTransaction". E.g. incidentID = 1 and CountOftransaction = 6, that means it's the 6th status change/transaction for incidentID 1.
  3. To get each incidents latest status for a date, my idea was to:
    Create vTable with CALCULATETABLE
    Filter this table using DATESINPERIOD to adjust the daterange when the measure is in a visual.
    Then Create a column with ADDCOLLUMS which checks for each incident ID's the highest "CountOftransaction" in the context that has been adjusted by DATESINPERIOD. 
    FILTER that in a ROW context to say that the CountOFtransaction needs to be equal the [@MaxTransaction]
    Count the IncidentID's where that result is not "Closed".
  4. Currently I have the expression below (hope this illustrates what I want to accomplish) but it’s not working as I'd hoped. Would it be possible to comment on how to create the correct calculation? If you can comment on 'why'  it's not working that be appreciated as well! Thanks in advance for the assistance! 

Open Incidents = 

VAR MaxDate = MAX('_Date'[Date]) 

VAR MinDate = 
CALCULATE(
    MIN(
        '_Date'[Date]
    ),
    REMOVEFILTERS()
)

VAR NoOFDays = ABS(Maxdate) - ABS(MinDate)

VAR Period = 
DATESINPERIOD(
    _Date[Date],
    Maxdate,
    -NoOFDays,
    DAY
)

VAR _CalcTable =
CALCULATETABLE(
    Raw_Transactions,
    Period
)

VAR _vTable =
ADDCOLUMNS(
    _CalcTable,
    "@MaxTransaction", 
        VAR Result =
        CALCULATE( 
            MAX( Raw_Transactions[CountOfTransaction] ), 
            ALLEXCEPT( Raw_Transactions, Raw_Transactions[IncidentId] ) 
        )

        RETURN
        IF(
            Result = Raw_Transactions[CountOfTransaction],
            Result
        )
)
    
RETURN 
CALCULATE(
    COUNTX(
        _vTable,
        [@MaxTransaction]
    ),
    Raw_Transactions[TransactionType] <> "Closed"
)

 

  •  

    Open Incidents = 
    
    VAR MaxDate = MAX('_Date'[Date]) 
    
    VAR MinDate = 
    CALCULATE(
        MIN(
            '_Date'[Date]
        ),
        REMOVEFILTERS()
    )
    
    VAR NoOFDays = ABS(Maxdate) - ABS(MinDate)
    
    VAR Period = 
    DATESINPERIOD(
        _Date[Date],
        Maxdate,
        -NoOFDays,
        DAY
    )
    
    VAR _vTable =
    CALCULATETABLE(
        ADDCOLUMNS(
            Raw_Transactions,
            "@MaxTransaction", 
                VAR Result =
                CALCULATE( 
                    MAX( Raw_Transactions[CountOfTransaction] ), 
                    ALLEXCEPT( Raw_Transactions, Raw_Transactions[IncidentId] ),
                    Period   ---Statement for the daterange needed to be added here---             
                )
    
                RETURN
                IF(
                    Result = Raw_Transactions[CountOfTransaction],
                    Result
                )
        ),
        Period, --Statement for the daterange needed to be added here--  
        Raw_Transactions[TransactionType] <> "Closed" ---Filter for not Closed needed to be here---
    )
        
    RETURN
    COUNTX(
        _vTable,
        [@MaxTransaction]
    )

     

    I've found a solution which gives me the results I'm looking for. 

    Performance wise it's not great, but it's good enough for now.

     

    Thanks for the assistance anyway!

8 Replies

  • Hi Thogen 

     

    Create a Running Total

    Incidents RT = 
    VAR MaxDate =
        MAX ( _Date[Date] )
    RETURN
        CALCULATE (
            DISTINCTCOUNT(Incidents[IncidentID]),
            KEEPFILTERS ( 'Incidents'[DateUTC] <= MaxDate
                && 'Incidents'[DateUTC]  >= MaxDate
                && Incidents[TransactionType] <> "Closed")
                ,
            ALL ( '_Date'))

     

    Joe

    • Thogen's avatar
      Thogen
      Frequent Visitor

      Hi Joe_Barry ,

       

      Thanks for assisting,

      The result from your measure seems (not 100% sure) to only be number of status changes for the given day. 

       

      Below is the result I'm looking for. #Open incident = 43.

       

      Is there some way to achieve this result?

       

      Thanks in advance!

  • Thogen's avatar
    Thogen
    Frequent Visitor
    IncidentIdDateUTCTransactionTypeCountOfTransaction
    102/Jan/23Created1
    102/Jan/23Closed2
    502/Jan/23Created1
    1803/Jan/23Created1
    103/Jan/23Updated3
    103/Jan/23Closed4
    1703/Jan/23Created1
    303/Jan/23Created1
    1403/Jan/23Created1
    904/Jan/23Created1
    2104/Jan/23Created1
    2104/Jan/23Closed2
    805/Jan/23Created1
    2605/Jan/23Created1
    2905/Jan/23Created1
    3005/Jan/23Created1
    4005/Jan/23Created1
    905/Jan/23Closed2
    2905/Jan/23Closed2
    5606/Jan/23Created1
    2406/Jan/23Created1
    3306/Jan/23Created1
    4406/Jan/23Created1
    4806/Jan/23Created1
    5106/Jan/23Created1
    4406/Jan/23Closed2
    7107/Jan/23Created1
    1407/Jan/23Closed2
    2607/Jan/23Closed2
    3807/Jan/23Created1
    3007/Jan/23Closed2
    5707/Jan/23Closed2
    5707/Jan/23Created1
    7208/Jan/23Created1
    7408/Jan/23Created1
    308/Jan/23Closed2
    508/Jan/23Closed2
    3508/Jan/23Closed2
    4008/Jan/23Closed2
    4808/Jan/23Closed2
    1408/Jan/23Updated3
    3508/Jan/23Created1
    1108/Jan/23Created1
    1308/Jan/23Created1
    1908/Jan/23Created1
    2008/Jan/23Created1
    4908/Jan/23Created1
    6208/Jan/23Created1
    1509/Jan/23Created1
    609/Jan/23Created1
    1009/Jan/23Created1
    2309/Jan/23Created1
    2709/Jan/23Created1
    3109/Jan/23Created1
    5009/Jan/23Created1
    5909/Jan/23Created1
    6509/Jan/23Created1
    8709/Jan/23Created1
    8809/Jan/23Created1
    9409/Jan/23Created1
    1309/Jan/23Closed2
    1509/Jan/23Closed2
    1709/Jan/23Closed2
    2409/Jan/23Closed2
    4909/Jan/23Closed2
    5109/Jan/23Closed2
    5609/Jan/23Closed2
    7209/Jan/23Closed2
    8709/Jan/23Closed2
    309/Jan/23Updated3
    1509/Jan/23Updated3
    1709/Jan/23Updated3
    2609/Jan/23Updated3
    5109/Jan/23Updated3
    1509/Jan/23Closed4
    9610/Jan/23Created1
    2810/Jan/23Created1
    4110/Jan/23Created1
    4210/Jan/23Created1
    4310/Jan/23Created1
    4710/Jan/23Created1
    5210/Jan/23Created1
    5410/Jan/23Created1
    6310/Jan/23Created1
    7610/Jan/23Created1
    8010/Jan/23Created1
    8410/Jan/23Created1
    410/Jan/23Created1
    10210/Jan/23Created1
    10910/Jan/23Created1
    1810/Jan/23Closed2
    2710/Jan/23Closed2
    4110/Jan/23Closed2
    4210/Jan/23Closed2
    5010/Jan/23Closed2
    6210/Jan/23Closed2
    3510/Jan/23Updated3
    310/Jan/23Closed4
    3510/Jan/23Closed4
    5110/Jan/23Closed4
  • Thogen's avatar
    Thogen
    Frequent Visitor

     

    Open Incidents = 
    
    VAR MaxDate = MAX('_Date'[Date]) 
    
    VAR MinDate = 
    CALCULATE(
        MIN(
            '_Date'[Date]
        ),
        REMOVEFILTERS()
    )
    
    VAR NoOFDays = ABS(Maxdate) - ABS(MinDate)
    
    VAR Period = 
    DATESINPERIOD(
        _Date[Date],
        Maxdate,
        -NoOFDays,
        DAY
    )
    
    VAR _vTable =
    CALCULATETABLE(
        ADDCOLUMNS(
            Raw_Transactions,
            "@MaxTransaction", 
                VAR Result =
                CALCULATE( 
                    MAX( Raw_Transactions[CountOfTransaction] ), 
                    ALLEXCEPT( Raw_Transactions, Raw_Transactions[IncidentId] ),
                    Period   ---Statement for the daterange needed to be added here---             
                )
    
                RETURN
                IF(
                    Result = Raw_Transactions[CountOfTransaction],
                    Result
                )
        ),
        Period, --Statement for the daterange needed to be added here--  
        Raw_Transactions[TransactionType] <> "Closed" ---Filter for not Closed needed to be here---
    )
        
    RETURN
    COUNTX(
        _vTable,
        [@MaxTransaction]
    )

     

    I've found a solution which gives me the results I'm looking for. 

    Performance wise it's not great, but it's good enough for now.

     

    Thanks for the assistance anyway!