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

Avg, Group by + set analysis

Hello everyone!

I have an issue with Set Analysis in Qlik Sense.

I want to calculate the Avg of a multiplication Group by a field: avg(aggr(importo*molt, scontrino)).

Well, now I want to calculate the same measure but in the previous year:

avg({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>}aggr(importo*molt, scontrino)).

In this way, my measure is not working, even if Qlik tells me that it's correct, as in the img below:

Cattura.PNG

In this way I don't see any value but if I move the {<**>} content after aggr(, I see the same value of the current year.

Cattura.PNG

Could anyone tell me what's wrong with this expression?

Thanks to all!

Labels (1)
1 Solution

Accepted Solutions
rubenmarin

Hi, if there is more than value for importo or molt per scontrino you need an agrgeation funciton to tell what to do with this differnt values, something like:

avg({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>}aggr(Sum(importo*molt), scontrino))

Maybe you need to add the set analysis also to this sum:

avg({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>}aggr(Sum({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>} importo*molt), scontrino))

View solution in original post

1 Reply
rubenmarin

Hi, if there is more than value for importo or molt per scontrino you need an agrgeation funciton to tell what to do with this differnt values, something like:

avg({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>}aggr(Sum(importo*molt), scontrino))

Maybe you need to add the set analysis also to this sum:

avg({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>}aggr(Sum({<Data={">=$(=Date(Addyears(Min(Data),-1))) <=$(=Date(Addyears(Max({1}Data),-1)))"}>} importo*molt), scontrino))