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
Thogen
Frequent Visitor

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. Thogen_0-1717409487367.png
  4. 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".
  5. 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"
)

 

1 ACCEPTED SOLUTION
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!

View solution in original post

8 REPLIES 8
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!

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
Joe_Barry
Super User
Super User

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




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn


Let's connect on LinkedIn


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. 

Thogen_0-1717419694612.pngThogen_1-1717419709317.png

 

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

Thogen_2-1717419729327.png

 

Is there some way to achieve this result?

 

Thanks in advance!

Hi @Thogen 

 

Try replacing DISTINCTCOUNT with COUNT




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn


Let's connect on LinkedIn


Slight impact but it doesn't seem to impact the result the way I want.

 

Thogen_1-1717420842323.png

 

Sorry @Thogen 

 

Maybe try replacing >= MaxDate with > MaxDate

If that doesn't work, add a custom column to show the last date before the new entry

LastStatusEndDate = 
VAR CurrentIncID = Incidents[IncidentID]
RETURN
    CALCULATE(
        MAX(Incidents[DateUTC]),
        FILTER(
            Incidents,
            Incidents[IncidentID] = EARLIER(Incidents[IncidentID]) 
            && Incidents[DateUTC] < EARLIER(Incidents[DateUTC] 
        )
    ))

Then redo the measure

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

If this doesn't work, Can you provide the Data? It doesn't look to sensitve

Joe




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn


Let's connect on LinkedIn


@Joe_Barry 

 

If tried a couple of times to post some data but it keeps deleting my post.

 

Your last solution only returns blanks

 

EDIT: It's seems to only be deleted when I post it as a reply. I've posted it regularly now and it seems to not have been deleted.

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.