Forum Discussion
Count first occurrence of string only
I have a db with a few million ITSM tickets. Each of those tickets has a Reference Number, as well as some Activity data, datestamps, plus the name of the person who has performed the activity.
I want to be able to count how many times each person has performed a 'KT Solution Linked' activity on each ticket, but only if there isn't already a 'KT Solution Linked' activity in the ticket. I've mocked up a table with some example data, the measures I'm currently using ("Old Stats") as well as what I might expect to see "New Stats").
Hi Anonymous,
I created a new [Tickets touched 2]. Please check it out in the attachment.
Tickets touched 2 = SUMX ( DISTINCT ( SELECTCOLUMNS ( ADDCOLUMNS ( 'Table1', "ifFirst", VAR temp = CALCULATE ( MIN ( Table1[ActivityDateStamp] ), ALLEXCEPT ( Table1, 'Table1'[RefNum] ), 'Table1'[Activity] = "KT Solution Linked" ) RETURN IF ( [ActivityDateStamp] < temp || ISBLANK ( temp ), 1, 0 ) ), "RefNumTemp", [RefNum], "ifFirstTemp", [ifFirst] ) ), [ifFirstTemp] )
Result = DIVIDE([Measure 2], [Tickets Touched 2]) * 100
Best Regards,
DaleHi Anonymous,
I would suggest you create a new post in this forum. It's a new topic.
Best Regards,
Dale
10 Replies
- AnonymousNot applicable
Imgur is blocked where I am, but I was going to suggest whether you have tried DISTINCTCOUNT?
- AnonymousNot applicable
Thanks Ross73312, I did try a couple variations of DISTINCTCOUNT but couldn't get the results I wanted.
- v-jiascu-msft
Microsoft Employee
Hi Anonymous,
Please try this measure and download the demo in the attachment.
Measure 2 = SUMX ( ADDCOLUMNS ( 'Table1', "ifFirst", IF ( [ActivityDateStamp] = CALCULATE ( MIN ( Table1[ActivityDateStamp] ), ALLEXCEPT ( Table1, 'Table1'[RefNum] ), 'Table1'[Activity] = "KT Solution Linked" ), 1, 0 ) ), [ifFirst] )
Best Regards,
Dale- AnonymousNot applicable
Thanks very much v-jiascu-msft, that works a treat. Much appreciated.
As a further refinement, what I'd like to be able to do is create a 'Link %' measure, which would be calculated as ([Measure 2] / [Tickets Touched] * 100). But the logic behind 'Tickets Touched' would need to change from "DISTINCTCOUNT of RefNum" to "DISTINCTCOUNT of RefNum, only where there hasn't been a previous occurrence of 'KT Solution Linked'". Is that something you might be able to assist with?
- v-jiascu-msft
Microsoft Employee
Hi Anonymous,
I created a new [Tickets touched 2]. Please check it out in the attachment.
Tickets touched 2 = SUMX ( DISTINCT ( SELECTCOLUMNS ( ADDCOLUMNS ( 'Table1', "ifFirst", VAR temp = CALCULATE ( MIN ( Table1[ActivityDateStamp] ), ALLEXCEPT ( Table1, 'Table1'[RefNum] ), 'Table1'[Activity] = "KT Solution Linked" ) RETURN IF ( [ActivityDateStamp] < temp || ISBLANK ( temp ), 1, 0 ) ), "RefNumTemp", [RefNum], "ifFirstTemp", [ifFirst] ) ), [ifFirstTemp] )
Result = DIVIDE([Measure 2], [Tickets Touched 2]) * 100
Best Regards,
Dale