Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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...
  • v-lili6-msft's avatar
    7 years ago

     

    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

     

    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

    Step4:

    Drag  IncidentID and two measure into visual

     

    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