Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to use Aggr, Max and Count together in Set Analysis?

Hi All,

I have a table in QlikView with fields like Month, Dept, Entry date, Exit date, Files(no of file records) and I want to count the number of people stayed overnight in any department on daily basis. Also, I have to find the maximum capacity of any department

This is what I did in QlikView to get the results:

MonthCalendar DateDept# of seatsSitting capacity of deptHeader 6
Jan30012015a

=COUNT(IF(CalendarDate>=[Date Entry] and CalendarDate<[Date Exit], Files))

How to get Max of "# of seats" aggregated at Dept level,  Month*Dept level and Calendar Date*Dept level.

Also the max value should repeat

Jan31012015s

=COUNT(IF(CalendarDate>=[Date Entry] and CalendarDate<[Date Exit], Files))

Feb05022015s

=COUNT(IF(CalendarDate>=[Date Entry] and CalendarDate<[Date Exit], Files))

Feb17022015a

=COUNT(IF(CalendarDate>=[Date Entry] and CalendarDate<[Date Exit], Files))

Mar01032015w

=COUNT(IF(CalendarDate>=[Date Entry] and CalendarDate<[Date Exit], Files))

Date EntryDate Exit
3001201517022015
3101201503022015
0602201513032015
1002201513032015
1802201513032015

please note that Calendar Date is from Master Calendar and is not linked to my database by any means

The Green column is what I want, Does anyone know how to get use all the aggr, count and max functions together

Any help will be highly appreciated

Regards,

Sagar Gupta

3 Replies
Not applicable
Author

hello sagar go through this link

http://www.analyticsvidhya.com/blog/2014/02/aggr/

Not applicable
Author

SET ANALYSIS

makes a dashboard lot more meaningful and action oriented. For example, if you just provide number of units sold by a product line in a month, it is good information, but it is not-actionable. If you add comparison against same month last year, last month or average of relevant product lines in this month, you have added context to the number. The business user can take more meaningful actions out of this report / dashboard.

QlikView has feature called SET ANALYSIS that provides us a way to add this context. Set analysis predefines the SET OF DATA that our charts / tables use. So, using a Set Expression, we can tell our object (chart / table) to display values corresponding to various sets of data (e.g. a pre-defined time-period, geographic region, product lines etc.). All of the examples, I mentioned above as part of adding context can be accomplished using Set Analysis in Qlikview.

Most of the QlikView Professionals think that SET ANALYSIS is a complex feature. Through this post, I am trying to change their conviction towards it.

What is SET ANALYSIS ?

Set Analysis can be understood by a simple analogy of how Qlikview works. We make selections on certain variables and the changes reflect in the entire application. This happens because through our selection, we have created a set of data which we want to use. In a similar fashion, using Set Analysis feature, we can pre-define the data to be displayed in our charts.

Some features and characteristics for Set analysis are:

  • It is used to create different selection compared to the current application selections
  • Must be used in aggregation function (Sum, Count….).
  • Expression always begins and ends with curly brackets { }

Example dataset:

SET ANALYSIS syntax broken down into three components:

  Identifiers: 

Identifier

Description

0

:Represents an empty set, no records

1

:Represents the set of all the records in the application

$

:Represents the records of the current selection

$1

:Represents the previous selection

Bookrmark01

:Represents the set of all records against bookmark ID or the bookmark name

Examples:-

In below example, Current year selection is 2012 and previous selection was 2013.

Operators :

  • It  works on set identifiers

Operator

Operator Name

Description

+

Union

Returns a set of records that belongs to union of sets.

-

Exclusion

Returns records that belong to the first but not the second

*

Intersection

Returns records that belong to both of the set identifiers.

/

Symmetric Difference

Returns a set that belongs to either, but not both of the set identifiers.

Examples:-

In below example, I have created a bookmark “BOOKMARK_1” for company selection A, B and C.

  Modifiers:  

  • Modifiers are always in angle brackets <>.
  • It consists multiple fields and all fields have selection criteria.
  • Condition of fields within modifiers bypass the current selection criteria.

  Dollar Sign Expansion: 

If we want to compare current year sale with previous year, previous year sales should reflect values in relation to current selection of year. For example if current selection of year is 2012, previous year should be 2011 and for current selection of year 2013, previous year is 2012.

“=Sum ({$<Year = {$ (=Max (Year)-1)} >} Sale) “

Above expression always returns sale for previous year. Here $ sign (Font color red) is used to evaluate the value for previous year. $ sign is used to evaluate expression and to use variables in set modifiers. If we have variable that holds last year value (vLASTYEAR) then expression can be written as:

“=Sum ({$vLASTYEAR)} >} Sale) “

  Indirect SET ANALYSIS: Function P() and E()

Let us take a scenario, where we want to show current sales of the companies who had sales last year.

Expression should be similar like:

=sum({$<Year={$(=Max(Year))},Company_Name={Companies who had sales last year}> } Sale)

First we have to identify companies who had sales last year. To fix this problem, we will use function P() that is used to identify values within a field and function E() that exclude values within a field.

Finally, we have expression:

=sum({<Year={$(=Max(Year))},Company_Name=P({<Year={$(=Max(Year)-1)}>}Company_Name)>}Sale)

This post was an example where we have brought out methods to use SET ANALYSIS in Qlikview. Have you used this feature before? If yes, did you find it useful? Do you have more nifty tricks to make Set Analysis more interesting? If not, do you think this article will enable you to use Set Analysis in your next dashboard?

Do let me know your thoughts on using this feature in QlikView.