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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Displaying value differently (if year(date)=A, display on table as B)

Hey guys,

I'm trying to improvise on a report but due to the lack of knowledge I am unable to do so, this is my code:

VehiTable:

Load "Maint_ Item Description",

          "No_" as No,

          date("Starting Date") as "StartDate",

    date("Ending Date") as "CompleteDate",

    Month("Starting Date") as "Month",

    Year("Starting Date") as "Year",

    Description,

    "Maint_ Item No_" as "Vehicle No",

    Remark

    where Year("Starting Date") >='2004';

SQL SELECT "Maint_ Item Description",

          "No_",

          "Starting Date",

    "Ending Date",

    Description,

    "Maint_ Item No_",

    Remark

FROM SQL-database"

where "Maint_ Item No_" LIKE 'VH%';

The output shows "1-1-1753" as the "Ending Date" if no value is recorded.

My point is to change it to showing "Null" instead of the "1-1-1753".

Anyway to correct this?

9 Replies
deepakk
Partner - Specialist III
Partner - Specialist III

hi,

try this code

if(len(trim(date("Ending Date") ) =0, nul(),date("Ending Date"))  as "CompleteDate"

Deepak

deepakk
Partner - Specialist III
Partner - Specialist III

A small correction. It should be NULL().

Deepak

Not applicable
Author

Hey Deepak,

Not sure if I am doing it correctly:

VehiTable:

Load "Maint_ Item Description",

          "No_" as No,

          date("Starting Date") as "StartDate",

    date("Ending Date") as "CompleteDate",

    Month("Starting Date") as "Month",

    Year("Starting Date") as "Year",

    if(len(trim(date("Ending Date") )=0, NULL(),date("Ending Date"))  as "CompleteDate",

    Description,

    "Maint_ Item No_" as "Vehicle No",

    Remark

    where Year("Starting Date") >='2004';

it returns "Error in expression: Len takes 1 perimeter"

deepakk
Partner - Specialist III
Partner - Specialist III

HI,

You need to add one more bracket. ")"

if(len(trim(date("Ending Date") ))=0, NULL(),date("Ending Date"))  as "CompleteDate",

Deepak

Not applicable
Author

Hmm, now it says "Field names must be unique within table"

deepakk
Partner - Specialist III
Partner - Specialist III

hi,

comment the above field

date("Ending Date") as "CompleteDate" or give a different name to it.

Deepak

Not applicable
Author

Hi, the code went through, but the date still shows as 1/1/1753

Do you mind explaining the code "if(len(trim(date("Ending Date") ))=0, NULL()," to me?

deepakk
Partner - Specialist III
Partner - Specialist III

hi,

remove the date function

if(len(trim(("Ending Date") ))=0, NULL(),date("Ending Date"))  as "CompleteDate",

len is used to check the length of a field . trim is ued for removeing spaces(if any).

We arechecking if The length of field is equal to zero then put null values else use the field.

We need to remove the date function.

Deepak

Not applicable
Author

I see, perhaps the database has assigned null date as "1-1-1753" thus the code didn't work.

Thank you so much for your help.