官术网_书友最值得收藏!

Adding conditional formatting

The business wants to see company sales figure by years and quarters. They want to highlight the entries where sales are below 5,000,000.

We will assume that database provides us the Quarter number and we need to convert that to words. We will use conditional formatting for that. Also, where sales is below 5 million, the cell will be shown in red using another conditional variable.

Getting ready

Create a simple list report with Year and Quarter (numeric) columns from the Sales / Time query subject.

Drag Quantity from Sales fact.

Group by Year and sort by Quarter.

How to do it...

Conditional formatting is used to enhance the report visualization. Here is how we can define conditional formatting in the created report:

  1. Go to Condition Explorer and click on Variables as shown in the following screenshot:
  2. Drag a new string variable from the Toolbox pane. Define the expression as [Query1].[Quarter (numeric)].
  3. Change the name of the variable to Convert_To_Words as shown in the following screenshot:
  4. Add four values for the variable; the numbers 1 to 4.
  5. Now add a Boolean variable and define it as [Query1].[Quantity]< < 5000000.
  6. Call this variable Show_Red as shown in the following screenshot:
  7. Go to the report page and select the Quarter (numeric) column. For the Text Source Variable property, select Convert_To_Words as the variable and then click on OK.
  8. Select the Quantity column and attach Show_Red to the Style Variable property.
  9. Now from Conditional Explorer, iterate through every condition for the different values of Convert_To_Words and set corresponding text for the Quarter column, that is, set First Quarter for value 1, and so on.
  10. For Show_Red as yes, select the Quantity column and change the background color to red.
  11. Run the report to test the output as shown in the following screenshot:

How it works...

Here we are defining conditional variables to trap the specific conditions and perform required actions on corresponding rows. There are three types of conditional variables: String, Boolean, and the report language variable.

The String variable

The String type of variable allows you to define different possible values that the expression can be evaluated into. You only need to define the values for which you need to define specific style or text. The rest are taken care of by the Other condition.

The Boolean variable

This variable is useful when the expression only evaluates into true or false and you need to format the entries accordingly.

The report language variable

This type of variable returns the language in which report is run by the user. You don't need to define any expression for this type of variable. You simply need to choose the languages for which you want to perform certain actions (like display titles in the corresponding language, or show the respective country flag in header).

Here, we have used one variable of String type and one of Boolean type.

There's more...

There are some other important style variables to check out.

The style variable property

By assigning a variable to this property, we can control the styling aspect of the object which includes font, colors, data format, visibility, and so on.

The text source variable property

By assigning a variable to this property, we can control the text/values being shown for that object. We can provide static text or a report expression. We can also choose to show value or label of another data item in the selected object.

In this example, we used this property to display the appropriate quarter name. Please note that it was possible to achieve the same result by putting a CASE statement in the data expression. However, the purpose here is to highlight the function of text source variable.

主站蜘蛛池模板: 化德县| 汉沽区| 柳河县| 翁牛特旗| 洛隆县| 台安县| 防城港市| 行唐县| 宁津县| 龙南县| 沐川县| 镇坪县| 鄂伦春自治旗| 朝阳县| 惠安县| 雅安市| 华蓥市| 阿坝县| 孝昌县| 加查县| 丰顺县| 东兰县| 海安县| 顺平县| 丰顺县| 含山县| 正蓝旗| 白河县| 桃源县| 海口市| 同江市| 塔城市| 泗水县| 水富县| 博野县| 汨罗市| 西青区| 海丰县| 丰宁| 成安县| 连平县|