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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
charlineklapu
Frequent Visitor

Measure to finde time difference between two ordered timestamps within one category

Hi all,

 

data looks as followed:

CustomerOpened onCaseStatus
Timestamp
 hh:mm:ss  
71218.11.2022 00:002100045In Progress18.11.2022 07:28    
71218.11.2022 00:002100045Closed18.11.2022 07:33    
71218.11.2022 00:002100146In Queue18.11.2022 07:40    
71219.11.2022 00:002103706New19.11.2022 07:37    
71219.11.2022 00:002103706New19.11.2022 07:37    
71219.11.2022 00:002103706Request Processed19.11.2022 07:37 00:04:00<24hn.FCR
71218.11.2022 00:002100146In Queue19.11.2022 07:41    
71218.11.2022 00:002100146In Queue21.11.2022 07:44    
71218.11.2022 00:002100146In Queue21.11.2022 07:53    
71218.11.2022 00:002100146In Progress21.11.2022 07:53    
71218.11.2022 00:002100146Request Processed21.11.2022 07:57  >24hFCR
         
12418.11.2022 00:002100546New21.11.2022 17:00    
12418.11.2022 00:002100546Request Processed21.11.2022 17:57  >24hFCR
         
23418.11.2022 00:002100946New21.11.2022 17:00    
23418.11.2022 00:002100946Request Processed21.11.2022 17:57 01:00:00<24hn.FCR
23418.11.2022 00:002100946in Queue21.11.2022 18:57    
23418.11.2022 00:002100946Request Processed24.11.2022 19:57  >24hFCR

 

I want to look at customers and his/her cases (One customer can have one-many cases). Once a case reached the status "request processed" at time stamp column it can either be "FCR" or "n.FCR" (FCR standing for first call resolution). A case can reach "request processed" multiple times. 

FCR would mean that after the status "request processed" was reached, there were no further changes (no matter which status) to the case within 24 hours. 

Therefore at each status "request processed" I want to have a column indicating wether it is "FCR" or "n.FCR". Shown by example column on top in orange color.

 

Thank you for your help!

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

Hi @charlineklapu .

 

According to your description, here is my solution, and please follow these steps.

Firstly, process the data and make sure that your columns "Opened on" and "Timestamp" are Date/time format.

vxiaosunmsft_0-1669604396483.png

And then use Power Query to add an index column.

And then create a calculated column.

 

Column =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[Timestamp] ),
        FILTER ( 'Table', [Index] = EARLIER ( 'Table'[Index] ) + 1 )
    )
VAR _b =
    DATEDIFF ( _a, [Timestamp], HOUR )
VAR _c =
    CALCULATE (
        MIN ( 'Table'[Timestamp] ),
        FILTER (
            'Table',
            [Customer] = EARLIER ( 'Table'[Customer] )
                && [Timestamp] > EARLIER ( 'Table'[Timestamp] )
        )
    )
RETURN
    SWITCH (
        TRUE (),
        [Status] = "Request Processed"
            && ISBLANK ( _c ), "FCR",
        [Status] = "Request Processed"
            && _b > 24, "FCR",
        [Status] = "Request Processed"
            && _b < 24, "n.FCR"
    )

 

Final output:

vxiaosunmsft_2-1669605503833.png

 

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ xiaosun

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

2 REPLIES 2
charlineklapu
Frequent Visitor

Hi,

 

thanks for your answer. 

 

How do I set up an Index column while using direct query in an sql analysis server datasource? While using this mode and going into power query editor I see no queries.

 

Thanks for the help again!

 

 

v-xiaosun-msft
Community Support
Community Support

Hi @charlineklapu .

 

According to your description, here is my solution, and please follow these steps.

Firstly, process the data and make sure that your columns "Opened on" and "Timestamp" are Date/time format.

vxiaosunmsft_0-1669604396483.png

And then use Power Query to add an index column.

And then create a calculated column.

 

Column =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[Timestamp] ),
        FILTER ( 'Table', [Index] = EARLIER ( 'Table'[Index] ) + 1 )
    )
VAR _b =
    DATEDIFF ( _a, [Timestamp], HOUR )
VAR _c =
    CALCULATE (
        MIN ( 'Table'[Timestamp] ),
        FILTER (
            'Table',
            [Customer] = EARLIER ( 'Table'[Customer] )
                && [Timestamp] > EARLIER ( 'Table'[Timestamp] )
        )
    )
RETURN
    SWITCH (
        TRUE (),
        [Status] = "Request Processed"
            && ISBLANK ( _c ), "FCR",
        [Status] = "Request Processed"
            && _b > 24, "FCR",
        [Status] = "Request Processed"
            && _b < 24, "n.FCR"
    )

 

Final output:

vxiaosunmsft_2-1669605503833.png

 

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ xiaosun

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.