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

Script If, Else Error?

Hi community,

I think I have a bug in the script.  If not please correct me.  I'm making a field of if(StatementA,FieldA,if(StatementB,FieldA,if(StatementC,FieldA))) as FieldB, I thought that this was how to do if/else in the script, but I found that for each of the ifs that are true FieldA is stored as a value for FieldB.  What am I missing, is there a way to rewrite this to get what I want which is exclusive if/else?  An example from my code is below.

if(match(date(Date),date(monthend(Date))),[Adj Close],if(match(date(Date),date(monthend(Date)-1)),[Adj Close],if(match(date(Date),date(monthend(Date)-2)),[Adj Close]))) as Close2,

4 Replies
chematos
Specialist II
Specialist II

I would write monthend out of date function: monthend(date(Date))

and I would use monthend(addmonths(date(Date),-1))

if(match(date(Date),date(monthend(Date))),[Adj Close],if(match(date(Date),date(monthend(Date)-1)),[Adj Close],if(match(date(Date),date(monthend(Date)-2)),[Adj Close]))) as Close2

I haven´t tried but I hope this helps.

The if clause seems fine

Not applicable
Author

It seems to me that you want to add the field [Adj Close] if it is the last 3 days of the month, rtight?

why don´t you simplify your if:

if (  date(Date) >= (date(monthend(Date)-2)) , [Adj Close] ) )

Not applicable
Author

Actually, I want the last day of the month that exists only.  I thought the code I used above would give me that for most cases, but it gives me all 3 days values if it exists for all 3 days. 

What I want is the value on the last day of the month it exists.

Not applicable
Author

I have already done something like it when loading (something like it):

// gets the last month

TEMP:

LOAD max(MT_MES) as maxcod

RESIDENT META;

LET vMaxMes = peek('maxcod');

// gets the last date of each month

drop table TEMP;

FOR i = 1 TO $(vMaxMes)

LAST_DATES:

LOAD $(i) AS COD_MONTH_TEMP,

max(date) as last_day

RESIDENT table;

NEXT

// gets the values on the last dates of each month

LAST_VALUES:

LOAD COD_MONTH_TEMP AS COD_MONTH

FROM LAST_DATES as DAY;

join

LOAD

COD_MONTH, DAY, VALUE

resident table;

Esta mensagem (incluíndo qualquer anexo) é dirigida apenas para o uso do indivíduo ou da entidade a qual está endereçada e pode conter informações privadas, proprietárias, privilegiadas, confidenciais que podem servir como evidências sob as leis aplicáveis ou em processos judiciais.

Caso você não seja o destinatário pretendido, você está aqui notificado que qualquer uso, disseminação, distribuição, ou cópia dessa comunicação é estritamente proibida. Se você recebeu essa comunicação por engano, notifique-nos imediatamente por telefone, e destrua essa mensagem se estiver impressa ou (ii) exclua imediatamente essa mensagem se esta for uma comunicação eletrônica.

Obrigado.

This message (including any attachments) is intended only for the use of the individual or entity to which it is addressed and may contain information that is non-public, proprietary, privileged, confidential, and exempt from disclosure under applicable law or may constitute as attorney work product.

If you are not the intended recipient, you are hereby notified that any use, dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, notify us immediately by telephone and destroy this message if this is printed or (ii) delete this message immediately if this is an electronic communication.

Thank you.