Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
PepeMontes
Partner - Contributor III
Partner - Contributor III

If Statement with dates

Hello dear experts,
I have a field called Fecha as a date, i'm trying evaluate it with a rate of dates depending of the value which evaluating Date field, once i  try to load data the next error comes(Attached image).
Loaderror.PNG

if(Fecha<Date(30/01/2015,'DD/MM/YYYY'),
if(PM < PE15,1,0),
if(Fecha>= Date(06/01/2016,'DD/MM/YYYY'),
if(PM < PE16,1,0),
if(Fecha<= Date(10/05/2016,'DD/MM/YYYY'),
if(PM < PE161,1,0),
if(Fecha<= Date(17/11/2017,'DD/MM/YYYY'),
if(PM < PE17,1,0),
if(Fecha<= Date(29/04/2019,'DD/MM/YYYY'),
if(PM < PE,1,0)
)
)
)
)
) as Sub_PE


Thanks for help.

Regards.

1 Solution

Accepted Solutions
PepeMontes
Partner - Contributor III
Partner - Contributor III
Author

Hello,
I tried this way and works for me, probably someone could use this in a future.

if (Fecha < Date(30/01/2015) and PM < PE15,
1,
IF((Fecha >= Date(30/01/2015)AND Fecha <= Date(06/01/2016))AND PM < PE16,
1,
IF((Fecha >= Date(06/01/2016)AND Fecha <= Date(10/05/2016))AND PM < PE161,
1,
If((Fecha >= Date(10/05/2016)AND Fecha <= Date(17/11/2017))AND PM < PE17,
1,
IF((Fecha >= Date(17/11/2017)AND Fecha <= Date(29/04/2019))AND PM < PE17,
1,0
)
)
)


)
)as Sub_PE

It seems the error comes from the range of dates.

Regards.

View solution in original post

4 Replies
robert99
Specialist III
Specialist III

I always go

  • if  thenEqual
  • or if and thenEqual
  • not if if if if

if(Fecha<Date(30/01/2015,'DD/MM/YYYY') and PM < PE15,1,0),  'Result1' ,
if(Fecha>= Date(06/01/2016,'DD/MM/YYYY'), 'result2',
if(PM < PE16,1,0),'results3'
etc
)
)
)
)
) as Sub_PE

 

PepeMontes
Partner - Contributor III
Partner - Contributor III
Author

Hello Robert,
I tired this way, but the same error comes too

Load *,
if(Fecha<Date(30/01/2015)
and PM < PE15,1,0),'Result1',
if(Fecha>= Date(06/01/2016)
and PM < PE16,1,0),'Result2',
if(Fecha<= Date(10/05/2016)
and PM < PE161,1,0),'Result3',
if(Fecha<= Date(17/11/2017)
and PM < PE17,1,0),'Result4',
if(Fecha<= Date(29/04/2019)
and PM < PE,1,0),'Result5'as Sub_PE

 

Regards

robert99
Specialist III
Specialist III

Sorry. My previous post may have mislead you

Do you want

if(Fecha<Date(30/01/2015,'DD/MM/YYYY') // I sometimes convert dates to numbers

and
PM < PE15,  //is PE15 a DUAL numerical value?

1,  // result =1

0) //else 0

as Sub_PE,

if so then you need something like

if(Fecha<Date(30/01/2015,'DD/MM/YYYY') 

and
PM < PE15, 

1, 

if(Fecha>= Date(06/01/2016,'DD/MM/YYYY') and
PM < PE16,

1,

0

)) as Sub_PE ,

 

 

 

 

 

PepeMontes
Partner - Contributor III
Partner - Contributor III
Author

Hello,
I tried this way and works for me, probably someone could use this in a future.

if (Fecha < Date(30/01/2015) and PM < PE15,
1,
IF((Fecha >= Date(30/01/2015)AND Fecha <= Date(06/01/2016))AND PM < PE16,
1,
IF((Fecha >= Date(06/01/2016)AND Fecha <= Date(10/05/2016))AND PM < PE161,
1,
If((Fecha >= Date(10/05/2016)AND Fecha <= Date(17/11/2017))AND PM < PE17,
1,
IF((Fecha >= Date(17/11/2017)AND Fecha <= Date(29/04/2019))AND PM < PE17,
1,0
)
)
)


)
)as Sub_PE

It seems the error comes from the range of dates.

Regards.