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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Subtract date/time based on text contained within a string

I have a ticketing system that audits field changes on ticket records. I am doing some research on how long it takes tickets to be raised in priority from low or medium to high or critical. I am also researching the total time it take a ticket from the time it is created to the time it reaches its final priority. Date examples with additional explaination below. My desired results are in hours rounded to 1 decimal.

 

My audit record table. I need to only look for the priority related changes within the "Field Changes" column (in bold).

 

AuditDateIncidentIDField Changes
2/26/2017 14:56INC000001771984Status: Assigned  (1)~Status_Reason: ~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: High  (1)~Priority Weight: 301
2/27/2017 16:44INC000001771984Status: Assigned  (1)~Priority Weight: 201~Urgency: 3-Medium  (3000)~Impact: 3-Moderate/Limited  (3000)~Priority: Medium  (2)
3/2/2017 12:37INC000001771984Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: High  (1)~
5/15/2017 14:49INC000001836727Status: In Progress  (2)~Priority Weight: 201~Impact: 3-Moderate/Limited  (3000)~Priority: Medium  (2)
5/15/2017 15:13INC000001836727Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: High  (1)~
5/15/2017 15:34INC000001836727Priority Weight: 201~Urgency: 3-Medium  (3000)~Impact: 3-Moderate/Limited  (3000)~Priority: Medium  (2)~
10/31/2017 16:57INC000001996080Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: Low  (3)~
11/1/2017 18:37INC000001996080Priority Weight: 201~Urgency: 3-Medium  (3000)~Impact: 3-Moderate/Limited  (3000)~Priority: Medium  (2)~
11/1/2017 18:43INC000001996080Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: High  (1)~
11/12/2017 21:13INC000002007779Priority Weight: 201~Urgency: 3-Medium  (3000)~Impact: 3-Moderate/Limited  (3000)~Priority: Medium  (2)~
11/14/2017 15:44INC000002007779Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: Critical  (0)~
1/3/2018 17:42INC000002059015Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: Low  (3)~
1/3/2018 18:56INC000002059015Priority Weight: 201~Urgency: 3-Medium  (3000)~Impact: 3-Moderate/Limited  (3000)~Priority: Medium  (2)~
1/3/2018 19:13INC000002059015Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: High  (1)~
1/3/2018 20:13INC000002059015Priority Weight: 301~Urgency: 2-High  (2000)~Impact: 2-Significant/Large  (2000)~Priority: Critical  (0)~

 

My second table already has the ticket ID listed (one record per ticket).

 

For the "Time to Critical/High" colum I need the time between the first record of each ticket to the first record that is high or critical in the field changes column below. If the first record of the ticket is high or critical then the time would be zero. If the ticket has 4 audit records (low, medium, high, then critical), then I would need the time between the low and high records. 

 

For the "Total Time" column, I simply need the time between the first and last record of each ticket regardless or priority.

 

IncidentIDTime to High/CriticalTotal Time
INC000001771984093.7
INC0000018367270.40.7
INC00000199608025.825.8
INC00000200777942.542.5
INC0000020590151.52.5



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

 

hi, @Anonymous

After my research, you could do these as below:

Step1:

Use SEARCH or FIND Function to add a column that based on text contained.

 

contained = 
IF (
    SEARCH ( "Priority: Critical", 'Table'[Field Changes], 1, 0 ) > 0,
    0,
    IF (
        SEARCH ( "Priority: High", 'Table'[Field Changes], 1, 0 ) > 0,
        1,
        IF (
            SEARCH ( "Priority: Medium", 'Table'[Field Changes], 1, 0 ) > 0,
            2,
            IF ( SEARCH ( "Priority: Low", 'Table'[Field Changes], 1, 0 ) > 0, 3 )
        )
    )
)

Note: Pay attention to the standard text format

 

3.JPG

Step2:

Add two measure by these formulas

Time to High/Critical =
VAR _mindatetime0or1 =
    CALCULATE (
        MIN ( 'Table'[AuditDate] ),
        ALLEXCEPT ( 'Table', 'Table'[IncidentID] ),
        FILTER ( 'Table', 'Table'[contained] = 0 || 'Table'[contained] = 1 )
    )
RETURN
    DATEDIFF (
        CALCULATE (
            MIN ( 'Table'[AuditDate] ),
            ALLEXCEPT ( 'Table', 'Table'[IncidentID] )
        ),
        _mindatetime0or1,
        MINUTE
    )
        / 60
Total Time =
DATEDIFF (
    CALCULATE (
        MIN ( 'Table'[AuditDate] ),
        ALLEXCEPT ( 'Table', 'Table'[IncidentID] )
    ),
    CALCULATE (
        MAX ( 'Table'[AuditDate] ),
        ALLEXCEPT ( 'Table', 'Table'[IncidentID] )
    ),
    MINUTE
)
    / 60

Step3:

Format the decimal for two measure

4.JPG

Step4:

Drag  IncidentID and two measure into visual

5.JPG

 

here is pbix, please try it.

https://www.dropbox.com/s/7t1gtd35nfwaoux/Subtract%20datetime%20based%20on%20text%20contained%20within%20a%20string.pbix?dl=0

 

Best Regards,

Lin

Community Support Team _ Lin
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

1 REPLY 1
v-lili6-msft
Community Support
Community Support

 

hi, @Anonymous

After my research, you could do these as below:

Step1:

Use SEARCH or FIND Function to add a column that based on text contained.

 

contained = 
IF (
    SEARCH ( "Priority: Critical", 'Table'[Field Changes], 1, 0 ) > 0,
    0,
    IF (
        SEARCH ( "Priority: High", 'Table'[Field Changes], 1, 0 ) > 0,
        1,
        IF (
            SEARCH ( "Priority: Medium", 'Table'[Field Changes], 1, 0 ) > 0,
            2,
            IF ( SEARCH ( "Priority: Low", 'Table'[Field Changes], 1, 0 ) > 0, 3 )
        )
    )
)

Note: Pay attention to the standard text format

 

3.JPG

Step2:

Add two measure by these formulas

Time to High/Critical =
VAR _mindatetime0or1 =
    CALCULATE (
        MIN ( 'Table'[AuditDate] ),
        ALLEXCEPT ( 'Table', 'Table'[IncidentID] ),
        FILTER ( 'Table', 'Table'[contained] = 0 || 'Table'[contained] = 1 )
    )
RETURN
    DATEDIFF (
        CALCULATE (
            MIN ( 'Table'[AuditDate] ),
            ALLEXCEPT ( 'Table', 'Table'[IncidentID] )
        ),
        _mindatetime0or1,
        MINUTE
    )
        / 60
Total Time =
DATEDIFF (
    CALCULATE (
        MIN ( 'Table'[AuditDate] ),
        ALLEXCEPT ( 'Table', 'Table'[IncidentID] )
    ),
    CALCULATE (
        MAX ( 'Table'[AuditDate] ),
        ALLEXCEPT ( 'Table', 'Table'[IncidentID] )
    ),
    MINUTE
)
    / 60

Step3:

Format the decimal for two measure

4.JPG

Step4:

Drag  IncidentID and two measure into visual

5.JPG

 

here is pbix, please try it.

https://www.dropbox.com/s/7t1gtd35nfwaoux/Subtract%20datetime%20based%20on%20text%20contained%20within%20a%20string.pbix?dl=0

 

Best Regards,

Lin

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Solution Authors
Top Kudoed Authors