QPR ProcessAnalyzer Expression Examples: Difference between revisions

From QPR ProcessAnalyzer Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 243: Line 243:
</pre>
</pre>


Average duration between the first occurrence of event A and last occurrence of event B. Average is calculated only for those cases that contain both events A and B Usecase: How long it takes to receive payment on average?
Cases average duration between the first occurrence of event A and last occurrence of event B. Average is calculated only for those cases that contain both events A and B. Usecase: How long it takes to receive payment on average?
<pre>
<pre>
Average(
Average(

Revision as of 12:33, 20 December 2017

The following examples assume that there is a filter with id 1. point. All KPI analyses also have an EventLog as a starting point, so expression written after the "EventLogById(1)." is a valid expression for KPI Analyses.

Get all event types that appear among the events:

EventLogById(1).EventTypes

Same as previous, except return event type names (Strings):

EventLogById(1).EventTypes.Name

Get a hierarchical array, where the upper level are EventTypes and the leaf level are Events:

EventLogById(1).EventTypes.Events

Get a hierarchical array, where the upper level are EventTypes and the leaf level are also EventTypes (all branches contain same EventTypes):

EventLogById(1).EventTypes:Events.Type
EventLogById(1).EventTypes:Events.TimeStamp

List all Events as leaf nodes which timestamp is after 2012-01-01:

EventLogById(1).EventTypes:Events.Where(Timestamp > DateTime(2012,1,1))

Calculates count of Events in the leaf nodes:

Count(EventLogById(1).EventTypes:Events.Where(Timestamp > DateTime(2012,1,1)))

Events are ordered beginning from the last one:

EventLogById(1).EventTypes.OrderByDescending(Events, Timestamp)

Same as the previous but with explicit context specified:

EventLogById(1).EventTypes.OrderByDescending(_.Events, _.Timestamp)

Shows all event types in a single comma separated string list:

EventLogById(1).(StringJoin(", ", EventTypes.Name))

Same as the previous, except in addition the EventTypes are ordered by name:

EventLogById(1).(StringJoin(", ", OrderByDescending(EventTypes, Name).Name))

List of all the Starter flows in a model from filterId=1:

RemoveLeaves(EventLogById(1).Flows:From.Where(IsNull(_)))

Go through the model recursively using the flows:

RemoveLeaves(EventLogById(1).Flows:From.Where(IsNull(_))).To.OutgoingFlows.To.OutgoingFlows.To

Traverse the model using events:

RemoveLeaves(EventLogById(1).Flows:From.Where(IsNull(_))).FlowOccurrences.To.NextInCase.NextInCase.NextInCase

All case attribute values within the model grouped by case attribute types:

Let("cases", EventLogById(1).Cases, EventLogById(1).CaseAttributes:(Let("attribute", _, cases.Attribute(attribute))))

All event attribute values within the model grouped by event attribute types:

Let("events", EventLogById(1).Events, EventLogById(1).EventAttributes:(Let("attribute", _, events.Attribute(attribute))))

Define a new user defined functions named "First", which takes the first item in an array:

Def("First", "a", GetAt(0, a));

The defined array can be used as follows:

First(Array(1, 2, 3))
returns: 1
Def("x", "a", Distinct(RecurseLeaves(OrderBy(EventLogById(a).Cases.Events, Type.Name), Type.Name)))

Function definition that uses itself, i.e. recursive functions:

Def("Fib", "a", If(a < 2, 1, Fib(a - 1) + Fib(a - 2)));
For("i", 0, i < 10, i + 1, Fib(i));

Takas all models, and show them in "id:name" format:

Models.StringJoin(":", [Id, Name])
Models.[Id, Name]

How many times activity "Sales Order Changed" occurs on average in cases?

Average(Count(Cases.Events.Where(Type.Name == "Sales Order Changed")))

What's the average cost per case of all sales order changes? (assumption Sales Order Changed activity has attribute Cost)

Average(Sum(Cases.Events.Where(Type.Name == "Sales Order Changed").Cost))

What's the total cost of all events that occured this year?

Sum(Sum(Cases.Events.Where(TimeStamp.Year == Now.Year).Cost))

What the total cost calculated from events, where cost is calculated by "unit cost" times "number of units"?

Sum(
    Cases.Sum(
        Events.(
            UnitCost * NumberOfUnits
        )
    )
)

In how many cases duration between "Invoice Sent" and "Payment Received" is more than 30 days?

Count(
    Cases.Where(
        (
            Max(
                Events.Where(
                    In(Type.Name, "et1", "et2")
                ).TimeStamp
            ) -
            Min(
                Events.Where(
                    In(Type.Name, "et1", "et2")
                ).TimeStamp
            )
        ).TotalMinutes
        > 60
    )
)

In how many cases "Invoice Sent" is not directly followed by "Payment Received"?

Count(
    RemoveLeaves(
        (
            Cases.Events.Type.Name
        ).Where(
            Count(
                IndexOfSubArray(
                    Array("et2", "et3")
                )
            ) <  Count(
                IndexOfSubArray(
                    "et2"
                )
            )
        )
    )
)

In how many cases "Payment Received" is before "Invoice Sent"?

Count(
    RemoveLeaves(
        (
                Cases.Events.Type.Name
        ).Where(
            Catch(
                Max(
                    IndexOfSubArray(
                        "et3"
                    )
                )
                < Min(
                    IndexOfSubArray(
                        "et1"
                    )
                ),
                false
            )
        )
    )
)

In how many cases, invoice wasn't paid within the due date? (i.e. invoice is due and it's not paid, or invoice was paid after due date)

Count(
  Cases.Where(
        (
            (Count(
                Events.Where(
                    Type.Name == "Invoice Paid"
                )
            ) == 0)
            &&
            (
                Catch(
                    GetAt(0, Events.[Invoice Sent].StopOnNull()) < Now
                , false)
                ||
                Catch(
                    GetAt(0, Events.[Due Date].StopOnNull()) < Now
                , false)
            )
        )
        ||
        (
            Catch(
                GetAt(0,
                    Events.Where(
                        Type.Name == "Invoice Paid"
                    ).TimeStamp
                )
                >
                Coalesce(
                    Catch(GetAt(0, Events.[Invoice Sent]), null),
                    Catch(GetAt(0, Events.[Due Date]), null)
                ),
            null)
        )
    )
  )
)

Cases average duration between the first occurrence of event A and last occurrence of event B. Average is calculated only for those cases that contain both events A and B. Usecase: How long it takes to receive payment on average?

Average(
    Sum(
        Cases.Events.Where(
            Type.Name == "Payment Received"
        ).(
            TimeStamp - GetAt(
                0,
                Case.Events.Where(
                    Type.Name == "Invoice Sent"
                )
            ).TimeStamp
        )
        .TotalMinutes
    )
)

What is the % of POs (cases) in a certain price range (case attribute "price")?

100 * Count(Cases.Where(Price > 1 && Price < 4)) / Count(Cases)

What is the average duration from event A directly followed by event B for those cases that directly continue to event C after B? (take the first occurrence if there are many)

Average(
    Cases.Let(
        "indexes",
        Box(
            Events.Type.Name
        ).IndexOfSubArray(
            Array("et2", "et3", "et4")
        )
    ).Where(
        Count(indexes) > 0
    ).(
        GetAt(
            GetAt(0,
                GetAt(0, indexes)
            ),
            Events
        )
    ).(
        NextInCase.TimeStamp - TimeStamp
    ).TotalMinutes
)

What is the average duration of completely received orders?

Average(
    Cases.Where(
        Count(
            Events.Where(
                Type.Name == "et3"
            )
        ) > 0
    ).(
        GetAt(0,
            Events.Where(
                Type.Name == "et2"
            ).TimeStamp
        )
        -
        GetAt(0,
            Events.Where(
                Type.Name == "et1"
            ).TimeStamp
        )
    ).TotalMinutes
)