Geocortex Reporting allows you to better understand and visualize critical relationships in your data through its highly-configurable and versatile reports.
One of the many different ways you can further enhance your reports are through the use of conditional expressions, which allow you to conditionally display a value or alter the appearance of your report based on criteria you specify in an expression.
In this Geocortex Tech Tip, we demonstrate some examples of how this is done.
Video Transcript
“Hi, my name is Darren and I am a developer on the products team. Today, we are going to take look at conditional expressions in Geocortex Reporting and how you can use them to modify your data, and enhance the appearance of your reports. Let’s take a look!
I have a fairly simple report here. I have the data source configured, which is a map service that has US census data about states and counties within those states, and I’m choosing to display county information, both the FIPS number and the population and median age.
For starters, I’ll just this go ahead and run this, and we can see what it looks like before we start modifying our report using conditional expressions. There we go, this is the information for the state of California; counties with associated data with each county.
We’re here to talk about conditional expressions but first, I’ll just review quickly what an expression is. An expression is a string or a recipe that gets parsed and processed into a value that can be displayed in the report. Expressions consist of field names, constant values like numbers, strings, booleans, they can also contain operators and functions.
So, conditional expressions involve one of these functions that I just mentioned, conditional expressions, in particular, make use of the ‘if’ function, so that can be used in a number of different ways.
For my first example, I’m going to demonstrate how the ‘if’ function can be used to modify the data we’re displaying for our population. So, I’m going to go ahead and select the text box that’s displaying my population value and then I’m going to click on that little ‘f’ in the corner here, look at my text expression. So, right now this is a very simple expression, showing the population of 2007 field. I’m going to delete that, I’m going to expand my functions down here, go to logical functions, just double click on this ‘if’. And so, the ‘if’ function consists of three parts. The first part of is a boolean expression, something that evaluates to true or false, the second value is going to be what we want to display if that condition evaluates to true, and then the third item in the function is what we want to display if the condition evaluates to false.
So, for this, I’m going to use our population 2007 field again. I’ll say if our population from 2007 was less than 10,000, the text that I want to display is ‘Low’. Then if that population happens to be above 10,000, we’re just going to display ‘High’. I’m going to click ‘OK’ there, save my report, and then run it again. We’ll see that my population column now displays these high and low values as compared to the actual numbers from before.
One very useful feature — I’m going to go back into my Expression Editor here — is I’m not restricted to just these two values, I can actually chain operators together. So, right now this expression says, my populations less than 10,000, let’s show a value of low or if it’s over, let’s display a value of high, but what if we want an intermediate value? What I can add at this point is I can add another check on my population, and say if my population is less than 50,000, let’s display a value of ‘Med’, otherwise we’re going to say ‘High’.
Ok, let’s save that, and run the report again. Now, we have low, medium and high values. You’re not limited to just those the three options – you can chain as many of these conditions together as you need to achieve your goal.
In addition to modifying your data, you can also modify the appearance of your report using conditional expressions.
For starters, I’m going to select this Median Age field, and then I’m going to select the Expression tab over here. We have a whole bunch of options available to us, we can set expressions for any of these properties, and thereby the modify the appearance of our report.
I’m going to say, let’s change the color of the text we displayed based on a condition. I’m going to change my foreground color, go down to my logical operators and add another ‘if’ condition.
If you’re not sure what all of the fields are that are available to you, you can go to the ‘Fields’ option here, and I can see, okay I want to work with my median age field. So, I’m going to say, if my Median Age is greater than 40, let’s change the color of our text or foreground color to green, otherwise, let’s leave that color as black. Say, ‘OK’ here, save my report, run it one more time. There we go!
We can see that I’ve changed the color, the foreground color, the color of our text to be green if the median age is over 40 years old. I’ve set that one expression for the appearance of my texts and I’m not restricted to just you know modifying one property, I can come in here, and let’s change something with a font. Let’s go ahead and create an expression that will make our font bold if it evaluates to true, otherwise we’ll leave the font as is or maybe we’ll make it bold. I’ll add the ‘if’ operator in there, again I’m working with my median age. This time, I’m going to save my median age as less than 40, I want bold to be true, otherwise, I want bold to be false.
You’ll notice that as I’m typing here, sometimes you’ll see a little red ‘X’ on the side over here. It’s just indicating that there’s a problem or issue with the expression that you’re currently typing. So, right now this expression is incomplete, and once I finish typing false, that validation warning goes away.
I click, ‘OK’ here, save my report, run it. For this report, I should see any ages below 40 as bold text, and ages above 40 in green.
So, this has just been a small sample of or small introduction into conditional expressions. I hope it’s been helpful and I encourage you to go into the Designer go to the Expressions tab and just look and see what options are available to you and see what kind of creative ways you can come up with to modify your data. Thank you for your time!”
Want to know more about Geocortex Reporting technology? Click the button below for product information, or to schedule a personal demonstration.