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

Use of Aggr

Dear all,

I need your help here

I have the following set of data:

MonthStoreIdRealForecast
01.Jan110090
01.Jan2150175
02.Feb1130125
02.Feb2180190

What I want to achieve is to have per store ID their forecast accuracy per month [1- (abs(forecast-real)/real))], and then the total per store will be the average of each month. So, something like this:

MonthStoreIdRealForecastForecast Accuracy
01.Jan11009090%
01.Jan215017583%
02.Feb113012596%
02.Feb218019094%

And then, the forecast accuracy per store will be their average per month:

StoreIdForecast Accuracy
193%
289%

Up until here... everything clear! The problem is when I try to get the total of both stores. What I want is to get the forecast accuracy per month (including both stores) and then the average:

MonthRealForecastForecast Accuracy
01.Jan25026594%
02.Feb31031598%
Total96%

In Qlikview, I have the following table:

Capture.PNG

As you can see I have managed to get the correct data for each store and the correct data for both stores together, but not in the same expression. The result that I want would be like this:

StoreIdForecast Accuracy
193%
289%
Total96%

Can anyone help me to get it? I am sure I am using correctly the Aggr function, but I think I am missing something to get the result that I want.

Thanks a lot!!

4 Replies
sunny_talwar

Try another Avg(Aggr()) on top of your already Avg(Aggr())

Avg(Aggr(Avg(Aggr(1-(fabs(Sum(TREV_FC) - Sum(TREV_Actuals))/Sum(TREV_Actuals)), NumMonth, HotelNameAjustado)), HotelNameAjustado))

or select a total mode of average if this is a straight table

sunny_talwar

My bad, try this:

If(Dimensionality() = 0,

Avg(Aggr(1-(fabs(Sum(Forecast) - Sum(Real))/Sum(Real)), Month)),

Avg(Aggr(1-(fabs(Sum(Forecast) - Sum(Real))/Sum(Real)), Month, StoreId)))

Capture.PNG

i_villafranca
Contributor
Contributor
Author

Hi Sunny,

Great it works!!

Just for me to understand, what does the "Dimensionality" function exactly?

Of course, everything is more complex than it seems, and now I have to add another dimmension to the exercise (I need a hierarchy dimension that will go from destination to store). Having the dimmension doesn´t work, so I am pretty sure I have to add something to the formula regarding "Dimensionality".

Can you help me one more time?

Thanks!

sunny_talwar

Read about dimensionality here:

How to use - Dimensionality()

Also read SecondaryDimensionality() used in Pivot tables: The second dimension... or how to use secondarydimensionality()