Condition to show a text message

Here, we will learn how to create a dynamic title in a text/image visualization using a condition to show the country name. If only one country is selected in the filter, it will display Sales of and the selected country name. If no county is selected in the filter, it will display the Sales of All Countries text. If two or more, but not all, countries are selected, it will display Sales of Some Countries.

We will add the following visualizations:

  • Filter pane with Country dimension
  • Text & image visualization with the Sales $ measure

Follow these steps to create the visualizations:

  1. Click on Edit button to enter the edit mode.
  2. Click on the Charts button on the asset panel, which is on the left-hand side of the screen, and find the Filter pane.
  3. Click on the Filter pane, and then drag and drop it into the empty space at the top of the sheet:

  1. Click on the Add dimension button and select Country in the Dimensions section:

  1. Resize the width and height of the filter panel to fit ten columns and one row of the grid:

To create the Text & image visualization, follow these steps:

  1. Click on the Charts button on the asset panel, which is on the left-hand side of the screen, and find the Combo chart.
  1. Click on the Text & image visualization, and then drag and drop this into the empty space on the right-hand side of the sheet.
  1. Click on Add Measure and select Sales $ in the Measures section.
  2. Fix the measure Number formatting to show a number with two decimal places.
  3. Resize the width and height of the filter panel to fit ten columns and two rows of the grid. The Text & image chart will look like this:

  1. Select the Text & image chart and go to the properties panel.
  2. Click on the Appearance heading, then click on the General section to expand it.
  3. Switch on the Show titles property, as shown in the following screenshot:

  1. Click on the fx button for the Title to open the expression editor, and then type the following expressions: =if (GetSelectedCount(Country) = 1,' Sales of '&Country, if (GetSelectedCount(Country) = 0, 'Sales of all Countries', 'Sales of some Countries')).
  2. Click on the Apply button to close the expression editor and save the expression.
  3. If no country is selected, the screen will look like the following screenshot:

  1. Click on the Done button to enter the visualization mode.
  2. Select Brazil in the Country filter.
  3. See how the title text changes when you select more countries in the Country field:

We learned how to create a nested if condition to evaluate three selection scenarios. First, we test whether one country is selected with the GetSelectedCount(Country) = 1 condition. Then we test whether none of the countries are selected with the GetSelectedCount(Country) = 0 condition. If none of these conditions are true, we show a text to say some countries are selected because there are two or more countries selected in the field.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset