Вы находитесь на странице: 1из 31

Advanced Set Analysis

MLT Vacations
Problem

Our goal here is to analyze specific flight patterns and compare the
current numbers to the previous year.
We will define our criteria using QlikView selections. Selections work well
in this situation, because they are easy to use within Set Analysis and
allow our users the flexibility to modify the criteria on-the-fly.
Due to the structure of our data, simply making the selections will not be
enough to get us the answers we are looking for. Our dataset
contains multiple records for each booking, one record for each
activity the customer will do during their trip. Bookings can also
include multiple customers, so we’ll have to verify that each booking
and customer we include matches the criteria.
Since the specific flight pattern we are looking for will only match one
record, we’ll need to include any customer where at least one record
matches our selected criteria.
Data

Our data is structured as follows. We want to include any customer that


takes a flight from MSP to CUN. We must be sure to include all
revenue associated with that customer, not just the revenue
associated with that specific flight.
Booking Customer Type Orig Dest Clients Air Rev
12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
Now let’s see what happens when we make some selections. We are looking
at flights from MSP to CUN.

Booking Customer Type Orig Dest Clients Air Rev


12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
Selecting our Origin includes any flight originating in MSP

Booking Customer Type Orig Dest Clients Air Rev


12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
We only want customers taking a flight from MSP to CUN, so this first
selection included a record we did not want.

Booking Customer Type Orig Dest Clients Air Rev


12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
Making our selection on the Destination eliminates the unwanted records.
Selecting both Origin & Destination requires that both values are present in a
single record, which is what we want for this exercise.

Booking Customer Type Orig Dest Clients Air Rev


12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
As you can see in the circled cells, including only the selected records will
result in us not counting all passengers and missing out on some revenue.

Booking Customer Type Orig Dest Clients Air Rev


12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
We’ll use Set Analysis to select every record for any customer who meets the
selected criteria.

Booking Customer Type Orig Dest Clients Air Rev


12345 A A MSP CUN 1 100
12345 A H 0 0
12345 B A MSP ATL 1 75
12345 B A ATL CUN 0 75
12345 B H 0 0
67890 A A MSP CUN 1 100
67890 B A MSP CUN 1 100
67890 A H 0 0
67890 B H 0 0
24680 A A FAR MSP 1 75
24680 A A MSP CUN 0 100
24680 A H 0 0
Implementation

The first thing we will do is build our expression in an intermediate table


using the natural dimensions.

Building your Expression in an intermediate table will be:


• Simpler to build
• Easier to troubleshoot
• More accurate
• Used directly in our final expression

In this example, our natural dimensions will be Booking and Customer


ID. Since this level of analysis is common for us, our dataset contains
one field that is a concatenation of both fields.
Set Analysis structure and terms

Here is the basic syntax for a Set Analysis expression and some terms I
will use throughout the presentation.

Sum({<FIELD = {'VALUE'}>} FACT)

Set Expression: {<FIELD = {'VALUE'}>}

Set Modifier: <FIELD = {'VALUE'}>

Element Set: {'VALUE'}


Building Our Revenue Expression

We will start with a basic Sum function:

Sum(AirRev)

BkgCust BkgType LegOrig LegDest BkgClients AirRev


12345A A MSP CUN 1 100
12345A H 0 0
12345B A MSP ATL 1 75
12345B A ATL CUN 0 75
12345B H 0 0
67890A A MSP CUN 1 100
67890B A MSP CUN 1 100
67890A H 0 0
67890B H 0 0
24680A A FAR MSP 1 75
24680A A MSP CUN 0 100
24680A H 0 0
Building Our Revenue Expression

Using Set Analysis and the 1 modifier, we will ignore all selections:

Sum({1} AirRev)

BkgCust BkgType LegOrig LegDest BkgClients AirRev


12345A A MSP CUN 1 100
12345A H 0 0
12345B A MSP ATL 1 75
12345B A ATL CUN 0 75
12345B H 0 0
67890A A MSP CUN 1 100
67890B A MSP CUN 1 100
67890A H 0 0
67890B H 0 0
24680A A FAR MSP 1 75
24680A A MSP CUN 0 100
24680A H 0 0
The P() Function [and E()]

We will bring our selections back in to play by utilizing the P() function

Set Modifiers with Implicit Value Definitions

• Only available in Set Analysis as Element Sets


• Represents the Element Set of Possible values and Excluded Values
respectively
• Can include a Set Expression
• Much faster than alternative methods, such as Concat
• Format:
{<FIELD = P({SET EXPRESSION} FIELD)>}
Building Our Revenue Expression

Using P() we will select all possible BkgCust values

Sum({1} AirRev)

BkgCust BkgType LegOrig LegDest BkgClients AirRev


12345A A MSP CUN 1 100
12345A H 0 0
12345B A MSP ATL 1 75
12345B A ATL CUN 0 75
12345B H 0 0
67890A A MSP CUN 1 100
67890B A MSP CUN 1 100
67890A H 0 0
67890B H 0 0
24680A A FAR MSP 1 75
24680A A MSP CUN 0 100
24680A H 0 0
Building Our Revenue Expression

Using P() we will select all possible BkgCust values

Sum({1<BkgCust = P(BkgCust)>} AirRev)

BkgCust BkgType LegOrig LegDest BkgClients AirRev


12345A A MSP CUN 1 100
12345A H 0 0
12345B A MSP ATL 1 75
12345B A ATL CUN 0 75
12345B H 0 0
67890A A MSP CUN 1 100
67890B A MSP CUN 1 100
67890A H 0 0
67890B H 0 0
24680A A FAR MSP 1 75
24680A A MSP CUN 0 100
24680A H 0 0
Variables to simplify Set Analysis expressions

Variables can be used in place of expressions saving you from


repeatedly typing the same expression which can lead to errors

Sum({1<BkgCust = P(BkgCust)>} AirRev)

Set a variable to represent your Set Expression


vSA = {1<BkgCust = P(BkgCust)>}

We can then simplify our expression using the variable


Sum($(vSA) AirRev)
Adding a Previous Year Expression

We add a Set Expression to the P() function to define the date span

Sum({1<BkgCust=P(
{<DeptDate={}>}
BkgCust)>} AirRev)
Adding a Previous Year Expression

We add a Set Expression to the P() function to define the date span

Sum({1<BkgCust=P(
{<DeptDate={}>}
BkgCust)>} AirRev)

Define the Element Set as a range

Sum({1<BkgCust=P(
{<DeptDate={‘>=7/1/2010<=12/31/2010’}>}
BkgCust)>} AirRev)

It is a good idea to use valid, pre-defined values when first constructing


the expression
Defining the Previous Year Span

Our current year span will be defined by a selection, we will use this
selection to define the previous year span

Start with the smallest, selected date


Min(DeptDate)
Defining the Previous Year Span

Our current year span will be defined by a selection, we will use this
selection to define the previous year span

Start with the smallest, selected date


Min(DeptDate)

Then modify it for the previous year


AddYears(Min(DeptDate),-1)
Defining the Previous Year Span

Our current year span will be defined by a selection, we will use this
selection to define the previous year span

Start with the smallest, selected date


Min(DeptDate)

Then modify it for the previous year


AddYears(Min(DeptDate),-1)

We will use similar logic for the largest value


AddYears(Max(DeptDate),-1)
Adding the Functions Using Dollar Sign Expansions

We must use Dollar Sign Expansions for our value functions

$(=AddYears(Min(DeptDate),-1))
$(=AddYears(Min(DeptDate),-1))
Adding the Functions Using Dollar Sign Expansions

We must use Dollar Sign Expansions for our value functions

$(=AddYears(Min(DeptDate),-1))
$(=AddYears(Min(DeptDate),-1))

If you think back to our expression with pre-defined values, we’ll


keep the Element Set the same, but replace the dates with our
selection-based functions inside Dollar Sign Expansions

{‘>= 7/1/2010
<= 12/31/2010 ’}
Adding the Functions Using Dollar Sign Expansions

We must use Dollar Sign Expansions for our value functions

$(=AddYears(Min(DeptDate),-1))
$(=AddYears(Min(DeptDate),-1))

If you think back to our expression with pre-defined values, we’ll


keep the Element Set the same, but replace the dates with our
selection-based functions inside Dollar Sign Expansions

{‘>=$(=AddYears(Min(DeptDate),-1))
<=$(=AddYears(Min(DeptDate),-1))’}
Tip: Dollar Sign Expansions in Set Expressions

When building Set Expressions with Dollar Sign Expansions, put your
expression into a Straight Table, but don’t give the expression a label
When the chart is rendered, the label will be your Set Expression with
the Dollar Sign Expansion evaluated

Sum({<DeptDate=
{‘>=$(=AddYears(Min(DeptDate),-1))
<=$(=AddYears(Min(DeptDate),-1))’}>}
AirRev)
Final Expressions

We now have working expressions for our selected date span and for the
previous year. These expressions can be used in tables or charts.
Since they are dynamic based on a selection, they can be modified
by the user on-the-fly

Sum({1<BkgCust=P(BkgCust)>} AirRev)

Sum({1<BkgCust=P({<DeptDate=
{‘>=$(=AddYears(Min(DeptDate),-1))
<=$(=AddYears(Min(DeptDate),-1))’}
BkgCust)>} AirRev)

The previous year expression definitely calls for variable simplification


Final Expressions

We now have working expressions for our selected date span and for the
previous year. These expressions can be used in tables or charts.
Since they are dynamic based on a selection, they can be modified
by the user on-the-fly

Sum($(vSA) AirRev)

Sum($(vSA_LY) AirRev)
Charting our Expressions

And here are our expressions in action


Set Analysis Summary

Here are some things to remember as you build your own expressions

• Simplify the problem by using an intermediate expression in a


table with natural dimensions
• Use variables where possible to simplify expressions

When working with dollar sign expansions:

• First hardcode a returnable value to verify that your Set


Expression is working
• Create a chart and enter your expression without a label to
determine what the dollar sign expansion is returning
Questions?
nmiller@mltvacations.com

Вам также может понравиться