Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
ariel_klien
Specialist
Specialist

Set analysis with different variables

Hello all,

I have a table with departments and month back to sum. like this:

DepartmentFromMonthToMonth
A121
B126
C123

for example: if we are in Aug.16 we need to take in

Department A sum of amount Aug.15 - July. 16   >=AddMonths(Date,-1) <=AddMonths(Date,-12)

Department B sum of amount Jan.15 - Feb. 16  >=AddMonths(Date,-6) <=AddMonths(Date,-12)

Department A sum of amount June.15 - May. 16  >=AddMonths(Date,-3) <=AddMonths(Date,-12)

I put the dates inside variables:

vDateFrom=AddMonths(if(GetSelectedCount(MonthName)=1,MonthName,Max(MonthName)),-FromMonth)

vDateTo=AddMonths(if(GetSelectedCount(MonthName)=1,MonthName,Max(MonthName)),-ToMonth)

in my set analysis this is my expression:

sum({<Date={">=$(=$(vFromDate))<=$(=$(vToDate))"},MonthName=>} Amount)

the expression working fine when i chose only one department. when more then one possible vToMonth is null.

my final table need to be:

DepartmentMonthNameSum
AAug. 16sum({<Date={">=01/08/2015<=01/07/2016"},MonthName=>} Amount)
AJuly 16sum({<Date={">=01/07/2015<=01/06/2016"},MonthName=>} Amount)
AJune 16sum({<Date={">=01/06/2015<=01/05/2016"},MonthName=>} Amount)
BAug. 16sum({<Date={">=01/01/2015<=01/02/2016"},MonthName=>} Amount)
BJuly 16sum({<Date={">=01/12/2014<=01/01/2016"},MonthName=>} Amount)
CAug. 16sum({<Date={">=01/06/2015<=01/05/2016"},MonthName=>} Amount)

how can i achieved that?

BR

Ariel

1 Reply
sunny_talwar

I think set analysis is evaluated once per chart. You might have to replicate what you are trying to do using if statement here.

Sum(If(Date >= AddMonths(Date,-ToMonth) and Date <= AddMonths(Date, -FromMonth), Amount)

UPDATE: I think you will need to use Aggr() function here and some other set analysis. May be if you can provide a sample which includes the date field, it might become easier to provide a solution here