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

Set Analysis with Addmonths

Hi All,

I want below expression in set analysis

=Sum(if(YearMonth>=Addmonths(CommonMonth,-2) and YearMonth<=Addmonths(CommonMonth,0),Sales))

Pls find the Sample app attached for reference.

Thanks in advance,

Regards,

Bhaskar

11 Replies
lironbaram
Partner - Master III
Partner - Master III

hei

why do you want the if clause in set analsys

you shuld know that in the set analsys

the  calculation of the condition is out side the table, which means the same result for all the table

i think it's not what you want

Not applicable
Author

Hey,

I dont want IF clause in Set Analysis.

I want to replace IF Clause with set analysis

I want the  same OutPut with Set Analysis  which  i am getting using IF Clause .

I have tried writing expreeion using Set Analysis but  the Expression is working only when i Select a CommonMonth.

Please refer my attachment .

martin59
Specialist II
Specialist II

Hi,

You have to do this :

Sum({<YearMonth={">=$(=AddMonths(CommonMonth,-2) <=$(=Only(CommonMonth))"}>} Sales)

Hope that helps you

Martin

lironbaram
Partner - Master III
Partner - Master III

hei

that what i mean

the field Commonmonth in the dimension get a lot of values

a set analsys is for one value

when you use set analsys the condition is calculated out side the table

which mean the condition sees all the commonmonth values  and cant calculate it

Not applicable
Author

HI Martin,

This is not working.

I am using common calendar.

martin59
Specialist II
Specialist II

So, you have to do that and you'll work on the max date (selections or not) :

Sum({<YearMonth={">=$(=AddMonths(Max(CommonMonth),-2) <=$(=Max(CommonMonth))"}>} Sales)

Hope that helps you

Martin

spsrk_84
Creator III
Creator III

Hi Bhaskar,

I think the result is not coming due to the date format in your expression .i.e the date formats are different when u use the addmonths functions... i changed them and used variables i am getting the result what is expected..

Please find the attached file

Regards,

Shiva

Not applicable
Author

Hi Martin,

Thanks  for ur quick reply.

Still this is not working ...

you can try on sample app which i had attached.

Not applicable
Author

Dear Shiva ,

Thanks For ur Reply..

I Know it is working  when I select a CommonMonth,But  I want this even when i dont select any thing in common month.

Which i am able to achieve using if condition.

Please check my First Charts Expression, which i have return with IF Condition.