3

QGIS 2.18.5

I'm trying to add a condition to my expression in my html/css map tips where if a value is 'null', the result will show 'no data available'.

I've got a screenshot of my map tip so far for a feature with populated values (the date and the number of years). Not all the features have a date and integer associated with them.

enter image description here enter image description here

What do I add to the code below?

<h1> [%"Local Auth"%] </h1> <h3> Date LAP Adopted</h3> <p> [% "Local Pl_1" %] </p> <h3> Five Year Housing Supply</h3> <p> [% "5 YHLS (#)" %] </p>

I tried

<h3> Date LAP Adopted</h3> <p> [%CASE WHEN "Local Pl_1" = ' ' THEN 'No Data Available' END%] </p>

but no luck.

2 Answers 2

3

Try coalesce()

<h1> [%"Local Auth"%] </h1>
<h3> Date LAP Adopted</h3> <p> [% coalesce("Local Pl_1", 'No Data Available') %] </p>
<h3> Five Year Housing Supply</h3> <p> [% "5 YHLS (#)" %] </p>
3

If your data it truly Null (and not a white space), then use IS NULL to detect it.

[%CASE WHEN  "Local Pl_1" IS NULL THEN 'No Data Available'
end%]

If the content of the field Local Pl_1 is to be displayed if it set (i.e. it is not null for some records), you can instruct QGIS to show it:

[%CASE WHEN  "Local Pl_1" IS NULL THEN 'No Data Available' ELSE  "Local Pl_1" 
end%]

--> if record 1 has a null "Local Pl_1" value, then No Data Available is displayed. If record 2 has the value "Local Pl_1" = Test, then Test is displayed in the maptip.

2
  • Sorry, how do you mean "Then if the data is not null, you can display it"? I didn't realise no entry was not the same and Null. Perhaps I need it coded for blank space instead
    – James B
    May 10, 2017 at 14:57
  • I clarified the post for the not-null case. Your example use a blank space (and you said doesn't work). If the solution using is null doesn't work either, you would have to check how "no data" is represented in your system (Null, empty string, white space etc).
    – JGH
    May 10, 2017 at 15:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.