Enquiry about Queries for SRSS

fabien prieur 41 Reputation points
2020-08-19T14:50:34.277+00:00

Hello everyone,

I write my problem here because I tried everything that I could, and I don't find a way to make what I want.

I need to make a report, for this, I'm using Microsoft SQL Server Report Builder to prepare Tables and Queries.

Here is one of my tables :

18872-01.png

The important information or my enquiry is that I've got an object (ECP), and this object will have different status during his processing. I will display all of his previous status with column : "From State > To state" with the date of the change with the Column "Date of change" like below :

18797-02.png

Now, I would like to calculate time elapse between each status In my column "Time Elapsed between status" => In my example, calculate time between (From state=new, To state=CAB) and (From state=CAB, To state=ON_HOLD), so time elapse from 12/12/2018 to 09/01/2019

Which Expression do I need to make it ?

18758-03.png

I don't have a clue which method I need to use to calculate time between result of a query in another query with difference between two raws.

I need your help on this guys !

Thanks by advance and let me know if you need further information.

Fabien

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,935 questions
0 comments No comments
{count} votes

Accepted answer
  1. Joyzhao-MSFT 15,591 Reputation points
    2020-08-20T02:41:40.56+00:00

    Hi,
    As Dan said,you could try the following query.

    =Datediff(DateInterval.Day,Fields!DOCINDEXDATE.Value,Previous(Fields!DOCINDEXDATE.Value))  
    

    The Previous function only supports field references in the details group. For example, in a text box in the details group, =Previous(Fields!Quantity.Value) returns the data for the field Quantity from the previous row.

    For more information about the use of the Previous function, please refer to: Report Builder Functions - Previous Function.

    Regards,
    Joy

    1 person found this answer helpful.
    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. DJAdan 671 Reputation points
    2020-08-19T15:17:54.36+00:00

    Hello Fabien,

    You can accomplish what you want by using the "Previous" function:

    =Datediff(DateInterval.Day,Fields!DOCINDEXDATE.Value,Previous(Fields!DOCINDEXDATE.Value))

    The Previous function will compare the value of the current row's field with the previous row's field value.

    I hope this helps.

    --Dan

    1 person found this answer helpful.

  2. DJAdan 671 Reputation points
    2020-08-20T15:10:48.883+00:00

    Hi Fabien,

    "Previous" will still work in your example. I assume your data is sorted by "object_ecp" and then date. Add a "Switch" statement like the example below.

    The trick is to compare your current Object Number with the prior Object Number.

    =Switch
    (
    Previous(Fields!object_ecp.Value) = Fields!object_ecp.Value, Datediff(DateInterval.Day,Fields!DOCINDEXDATE.Value,Previous(Fields!DOCINDEXDATE.Value)),
    True, Nothing
    )

    I hope this helps.
    --Dan

    1 person found this answer helpful.

  3. fabien prieur 41 Reputation points
    2020-08-20T05:15:03.267+00:00

    Hello Joy,

    I didn't know this function, but that's work perfectly !

    Thank you very much for the solution !

    Regards,

    Fabien

    0 comments No comments

  4. fabien prieur 41 Reputation points
    2020-08-20T09:48:53.63+00:00

    Hello again,

    I come back to you for another (the last I guess) question !

    Your solution work perfectly, BUT, the problem is that I've got multiple OBJECT (ECP) that I replace in the following image by number 1,2,3.

    Is there a way to calculate previous raw like before, only on the object and to not have the calculation made between 2 object (because this is nonsense).

    In my example :
    19151-04.png

    For the Object 2, he is calculating time elapsed between his time and the last time of Object 1, but what I want for Object 2 is nothing (null), I would like to reset te count between each object.

    Let me know if you have it in your pockets !

    And thanks again guys !

    Fabien

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.