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

Get Field Selections Syntax with IF statements

Hi All,

I could not run the calculated field below, this is the logic but I am making a mistake somewhere.

=if(GetFieldSelections([Period])='Daily', sum({<DATE= {'$(vYesterday)'}>} IPCOUNT),
if(GetFieldSelections([Period]),'Weekly', sum({<DATE= {'$(vPreviousWeek)'}>}IPCOUNT)
if(GetFieldSelections([Period]),'Monthly',sum({<DATE= {'$(vPreviousMonth)'}>}IPCOUNT))))

Labels (1)
1 Solution

Accepted Solutions
Milaf
Contributor III
Contributor III
Author

This is the solution;

if(GetFieldSelections([Period]) ='Daily',
(sum({<Todayly= {'$(vYesterday)'}>} IPCOUNT1) + sum({<Todayly= {'$(vYesterday)'}>} IPCOUNT2) + sum({<Todayly= {'$(vYesterday)'}>} TotalCount)),
if(GetFieldSelections([Period])='Weekly',
(sum({<Todayly= {'$(vPreviousWeek)'}>} IPCOUNT1) + sum({<DATE= {'$(vPreviousWeek)'}>} IPCOUNT2) + sum({<Todayly= {'$(vPreviousWeek)'}>} TotalCount)),
if(GetFieldSelections([Period])='Monthly',
(sum({<Monthly= {'$(vAy)'}>} IPCOUNT1) + sum({<Monthly= {'$(vAy)'}>} IPCOUNT2) + sum({<Monthly= {'$(vAy)'}>} TotalCount))
)))

View solution in original post

6 Replies
MatheusC
Specialist
Specialist

Hi, @Milaf 

try correcting the syntax like this

if(GetFieldSelections([Period])='Daily',sum({<DATE= {'$(vYesterday)'}>} IPCOUNT),
if(GetFieldSelections([Period])='Weekly', sum({<DATE= {'$(vPreviousWeek)'}>}IPCOUNT),
if(GetFieldSelections([Period])='Monthly',sum({<DATE= {'$(vPreviousMonth)'}>}IPCOUNT))))


Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
Milaf
Contributor III
Contributor III
Author

Thank you Matheus, I didn't notice the syntax there but I changed it when I saw it 🙂

Finally, I tried the one below, but the monthly one never works. I could not get the total of the previous month 😞

=if(GetFieldSelections([Period])='Daily',sum({<DATE= {'$(vYesterday)'}>} IPCOUNT),
if(GetFieldSelections([Period])='Weekly',sum({<DATE= {'$(vPreviousWeek)'}>} IPCOUNT),
if(GetFieldSelections([Period])='Monthly', sum({<MONTH= {'$(vMonthly)'}>} IPCOUNT)
)))

Milaf
Contributor III
Contributor III
Author

My Monlty variable is; 
     =Date(MONTH-31, 'DD.MM.YYYY')

I wrote above "sum({<MONTH= {'$(vMonthly)'}>} IPCOUNT) " works when I write 01.10.2023 instead of the variable in the formula. "sum({<MONTH= {'01.10.2023'}>} IPCOUNT) but it does not detect the variable value even though it is correct.

MatheusC
Specialist
Specialist

@Milaf 

try this in your variable

vMonthly
$(=Date(MonthStart(AddMonths(today(1),-1)),'DD.MM.YYYY'))


Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
MatheusC
Specialist
Specialist

@Milaf 

Close the topic and mark the solution as accepted

Thanks!

Did you find a solution to your question? Mark the solution as accepted and if you found it useful, press the like button!
Milaf
Contributor III
Contributor III
Author

This is the solution;

if(GetFieldSelections([Period]) ='Daily',
(sum({<Todayly= {'$(vYesterday)'}>} IPCOUNT1) + sum({<Todayly= {'$(vYesterday)'}>} IPCOUNT2) + sum({<Todayly= {'$(vYesterday)'}>} TotalCount)),
if(GetFieldSelections([Period])='Weekly',
(sum({<Todayly= {'$(vPreviousWeek)'}>} IPCOUNT1) + sum({<DATE= {'$(vPreviousWeek)'}>} IPCOUNT2) + sum({<Todayly= {'$(vPreviousWeek)'}>} TotalCount)),
if(GetFieldSelections([Period])='Monthly',
(sum({<Monthly= {'$(vAy)'}>} IPCOUNT1) + sum({<Monthly= {'$(vAy)'}>} IPCOUNT2) + sum({<Monthly= {'$(vAy)'}>} TotalCount))
)))