Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Different aggregation criteria and sumif questions

Hello everybody,

i am kinda new with the product and I like it a lot.

I am working on a project for a telco company and I need to solve 2 problems:

- in a table I have to compare the number of the Customer of the selected date with the number of the Customers in a different and fixed date.

For example I select the data from 1 to 15 april and I want to compare the selection with my data at 31/03. The 1-15 april column is not a problem, is a simple aggregation and i have done it quickly. I am stuck at the other one.

I tried to use the following formula: =SUM(IF([Data riferimento]='31/03/2010', #USIM)) but is not working..

- The biggest problem i have is about multiple aggregation criteria. Most easy example is number of Customers. I have a simple logic hierarchy (zone-region). I have the data by zone and is easy to aggregate them into region by using sum().

The problem arise with time. If I select multiple days I would like the data to be aggregated by average and not by sum. I solved this by now aggregating with sum() and dividing the result for the number of selected days.. Is this correct or there is a more elegant way?

thanks a lot for your help,

Lorenzo

1 Solution

Accepted Solutions
johnw
Champion III

I believe you want this:

sum({<[mese]=,[giorno]=,[Data riferimento]={'$(=monthend(max([Data riferimento]),-1))'}>} [#USIM])

You have to specify [mese]=,[giorno]= to tell it to ignore the values in those fields. Otherwise, simply telling it the right value for Data riferimento will result in no data being found (because it's still ALSO trying to match mese and giorno). If your real application has additional fields in the calendar that are selectable, you'll have to specify all of them like that so that they'll be ignored.

In a set analysis expression, single quotes indicate a literal, double quotes indicate a search string. If you have one value, double quotes will still work (it will search for and find that one value), but I suggest using single quotes to indicate that it's a literal. I think it's a good habit to be in.

The $(=...) is a "dollar sign expansion". These are always evaluated first, and the result is inserted into the expression as if you had typed that exact text. So if this expression returns 31/3/2010, the first pass for QlikView is to literally convert it to this:

sum({<[mese]=,[giorno]=,[Data riferimento]={'31/3/2010'}>} [#USIM])

So we're using dollar sign expansion to get our "string literal" that we were looking for.

In this case, I doubt that the synthetic key being created is a problem. In fact, it should be internally almost identical to what would happen if you concatenated the two values yourself. Synthetic keys OFTEN indicate a problem, and you USUALLY want to only link on a single key. But in this case, at least on the surface, it looks fine to me to just leave the synthetic key alone.

In this case, we didn't need a date() expression in the set analysis because Data riferimento was stored in the default date format for this document. Otherwise we'd have needed to specify the format explicitly, like indicated in earlier posts. In set analysis, yes, you'll have to compare "like to like" in regards to dates. It's doing the same thing as would happen if you started typing the expression in a list box. If you type the numeric equivalent of a date in a date list box, it won't find the date. Maybe it should, but it doesn't, and set analysis is similarly limited.

"Island" tables with disconnected dates are very useful. They also have a lot of drawbacks. They're a quick and dirty solution to many problem, but there's usually a better solution.

View solution in original post

17 Replies
Not applicable
Author

Hi

For the first issue, check in script how your date are formated :

It should be :

SET DateFormat='DD/MM/YYYY';

For your second point you can use AGGR function :

your expression should be :

= aggr( sum( var) , Date) / Count( Distinct Date)

It's the mean of var by day.

regards

jj

Not applicable
Author

for the second question you can use Avg aggregation function

Not applicable
Author

Hi mate,

i appreciated a lot your answer! you actually identified a part of the problem.

But, now that i have solved it, is still not working.

It only works if I have that specific date selected. If I change the date, it stops working. Is there a way to "detach" the single expression or I have to create a different table and detach it?

About the aggr function i'll try it soon 🙂

thanks again

Not applicable
Author

nobody? this is driving me crazy...

Not applicable
Author

Hi Nefion

Can you share your app (or a simplified example) with a small dataset and show
- a selection example that works
- a selection example that does not work

Juerg

Not applicable
Author

Sure 🙂

here attached a sample. If you select a data range in the top bar that includes the "31/03/210" (for example by selecting "March") it works nicely and the "Previous" column of the table is filled.

If you select a different data range (for example the "19/4/2010") the Column "previous" only shows 0.

thanks again for your precious help

Lorenzo

Not applicable
Author

Hi Lorenzo

My comments:
1) If you look at the internal table view you can see that QlikView has created an additional table to resolve your combination key "Nome Pool" and "Codice Pool". You should always try to create a single key for the links e.g. simply concatinate the 2 values in both tables

2) In the Customers table you have hard coded the date for the Previous Expression. You get ony previous values when 31/03/2010 is selected and for this current and previous is the same, difference always 0.
Question is: what is "Previous" for you, previous day, previous week, previous month, previous year? In addition do you expect a single date is selected only or can it also be a date range?
Your date in the if condition will need to be calculated from the currently selected date / date range. I should be able to help you with the formula once you define what you expect.

3) I see that your "delta" column has a "ratio" formula, so would you like to show delta or ratio?

Regards

Jürg

Not applicable
Author

Normal 0 false false false EN-US X-NONE X-NONE

wow mate, thanks a lot for all these feedbacks!!

my answers:

1) thanks you're right. I'll improve it for sure

2) Previous for me is the number of the Customer of the last day of the previous month of the selected date. So if I select the 19/04 I expect to see the values of 31/03. When i tried this for the first time I used the "monthsend" function but wasnt able to properly set it up I guess... If you could help wiht that i will apreciate a lot.

The selection in the final version will be both a range or a single date

3) Delta is the % of variation between actual and previous

thanks a lot again

Lorenzo

Not applicable
Author

Lorenzo

when you select a date range covering multiple month's, you expect to get the value in relation to the date range start or date range end?

Juerg