Conditionally display a label based on the number of rows in a PixelPerfect report
Reading this tutorial you will learn how to create a label in a PixelPerfect template that will be conditionally displayed based on the number of rows in a table. This is useful, for example, when you want to display a word when the table contains a single row, and the same word in plural when the table contains many rows.
Create a PixelPerfect template as usual and add the details band of a table in it. Then add the Group Footer.
Drag and drop a Label from the right toolbar into the Group Footer band and align it with with the column. This label will display the number of Salesmen (so when the table contains more than one row).
Open the smart tag of the label by clicking on the upper right corner arrow. Expand the Data Binding drop down menu and select the column Salesman. Then click on the three dots on the right of Summary to open the related window.
In the Summary function select Count and in the Summary running radio button select Group.
Click on the three dots on the right of Format string. In the General Category enter " Salesmen" in the Suffix form. Note the space at the beginning of the string. Then confirm with OK two times.
Scroll down the label property grid and set Visible to No
So the label is created but it is invisible. Now we will create a formatting rule that makes the label visible only when there are more than one row in the table. Open the formatting rules editor by clicking on the dots.
Click on Edit Rule Sheet then click on the green plus button to open a new rule in the editor. Give a meaningful name to the rule, like Many. Then open the Condition Editor and insert the formula
Iif([CH192_Level - Top 10 Salesman].Count() > 1, True , False)
It returns the boolean True only when the table has more than 1 row. Confirm with OK.
Set the Visible parameter to YES. So when the condition is met it will return true and the formatting rule applied. The formatting rule makes the label visible.
Click on Close and associate the formatting rule with the label by selecting it and pressing the > button. Then click on OK.
Run a report Preview in a case with many lines and the label is visible.
Add a filter to the report in order to select a single table row and run a new report preview. The label disappears.
Use copy and paste to create a new copy of the same label, then open the smart tag of the new label. Change the format string to Salesman directly in the form. Then open the Formatting Rules editor by clicking on its dots. Remove the Many formatting rule by clicking on the < arrow and create a new rule.
Call the new rule One, set Visible to Yes and insert the Condition formula:
Iif([CH192_Level - Top 10 Salesman].Count() == 1, True , False)
It is the same as before a part the equal symbol ==. It returns true when the table has a single row.
Close the editor and apply the new One rule to the label. Confirm with OK. Run a report preview. You will see the second created label.
Now you have two labels, one appears when there is a single row in the table and the second appears when the tables has many rows. Overlap the two labels so the will appear always in the same position in the generated reports.
Now generated reports will have the correct string based on table rows number.