Qlik Community

QlikView Documents

Documents for QlikView related information.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More

Missing Manual - Before() and After()

Missing Manual - Before() and After()

1f4fe19.jpgHave you ever wondered how the examples from the Qlikview help may look like?

Please see below and enjoy responsibly...

Before () and After()

Description


Returns the value of expression evaluated with a pivot table's dimension values as they appear in the column before the current column within a row segment in the pivot table. This function returns NULL in all chart types except pivot tables.

On the first column of a row segment a NULL value will be returned, as there is no column before this one.

If the table is one-dimensional or if the expression is preceded by the total qualifier, the current row segment is always equal to the entire row.

If the pivot table has multiple horizontal dimensions, the current row segment will include only columns with the same values as the current column in all dimension rows except for the row showing the last horizontal dimension of the inter field sort order. The inter field sort order for horizontal dimensions in pivot tables is defined simply by the order of the dimensions from top to bottom.

Specifying an offset greater than 1 lets you move the evaluation of expression to columns further to the left of the current column. A negative offset number will actually make the before function equivalent to a after function with the corresponding positive offset number. Specifying an offset of 0 will evaluate the expression on the current column. Recursive calls will return NULL.

By specifying a third parameter n greater than 1, the function will return not one but a range of n values, one for each of n table columns counting to the left from the original cell. In this form, the function can be used as an argument to any of the special Chart Range Functions.

  • Returns value from preceding (Before)or following (After) column
  • Returns values only in Pivot Table otherwise NULL.
  • Works only with Horizontal dimension.
  • Equivalent to below() and above() for vertical Pivot Table dimensions.

Data Model:

(Copy and Pasted below code into Edit Script window and reload)

LOAD * inline

[

Product ,Category ,Sales

Salt ,White, 30

Salt, Brown ,40

Salt ,Red ,30

Sugar ,White ,10

Sugar ,Brown ,20

Sugar ,Red ,20

Wine ,White ,40

Wine ,Brown ,30

Wine ,Red ,10

]

Example 1:

Let's build a Pivot Tables with Product as dimension and expressions as below:

The left hand side shows an ordinary use of Sales the right hand side result from our new expression.


                sum( Sales )    ----------->  before(sum( Sales ) )

01-Apr-15 4-39-16 PM.jpg


Salt value has been assigned to Sugar,

Sugar to Wine,

Salt  is now NULL .(there is no column before this one)

                sum( Sales )    -----------> after(sum( Sales ) )

after.jpg

Here we see the opposite result:

Sugar value has been assigned to Salt,

Wine to Sugar

and Wine is  NULL (no column after this one)

Example 2


Specifying the second criteria as 2 we shifted all values by 2 columns right or left.

                                before( sum( Sales ), 2 )

3.png

                                after( sum( Sales ), 2 )

4.png

Example 3


before(total sum( Sales ) )

after(total sum( Sales ) )

When using with one dimension this expression returns values as if we have used ordinary  before/after (Sum(Sales))

2015-04-02 02_37_23-QlikView Personal Edition - [C__Users_Katarzyna_Desktop_Before.qvw_].png

For more than one dimension the return value will be based on last column of the first(top) dimension and then appropriate columns for the second dimension.

2015-04-02 03_07_52-QlikView Personal Edition - [C__Users_Katarzyna_Desktop_Before.qvw_].png

Salt and Sugar have been omitted leaving Wine as the last column

Example 4


rangesum (Before(sum(Sales),1,2))

RangeSum() takes 3 parameters

-expression ---> Before/After(sum(Sales),

-offset of columns--->1

-number of columns to sum--->2

                                                               

                                                                  sum(Sales)                            rangesum (Before(sum(Sales),1,2))

2015-04-06 06_16_03-Microsoft Excel - Book1.png


In our example we are shifting our calculation one column to the right:

-Salt -  As there is no column before Salt this column has been ignored

-Sugar -we are shifting our calculation one column to the left (Salt)  and are summing previous two columns.

As there is no column before Salt the final result is value of Salt alone.

-Wine- by shifting calculations one column to the left(Sugar) and summing two previous columns we getting 100+50=150


                    sum(Sales)                            rangesum (after(sum(Sales),1,2)

2015-04-06 07_38_18-Microsoft Excel - Book1.png

In this example we are shifting our calculation one column to the right:

-Wine -  As there is no column after Salt this column has been ignored

-Sugar -we are shifting our calculation one column to the right(Wine) and aresumming previous two columns.

As there is no column after Wine the final result is value of Wine alone.

-Salt- by shifting calculations one column to the right(Sugar) and summing two previous columns we getting 50+80=130

Still feeling hungry?

How to use - Only()

Do you Qualify?- How to use QUALIFY statement

How to use - Dimensionality()

Missing Manual - GetFieldSelections() + Bonus Example

MaxString & MinString - How to + examples

The second dimension... or how to use secondarydimensionality()

Comments
carbal1952
Contributor II

I like so much this kind of info.

A different view from usual manuals  and current books.

Thanks.

CB:

daniel_kusiak
Contributor II

This is how manuals should look like - nice and easy

Thnx Robert

Not applicable

Robert, many thanks to you!

This is very helpful!

0 Likes
Partner
Partner

a wonderfull example. very useful!!

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎2015-03-31 08:22 AM
Updated by: