Like what you see? Have a play with our trial version.

Error rendering macro 'rw-search'

null

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

Anchor
top
top

Table of Contents
classcontents

Overview

Styleclass
ClasstopLink

top

HTML
<iframe width="700" height="394" src="https://www.youtube.com/embed/1O7ogaEZ4p0?color=white" frameborder="0" allowfullscreen></iframe>

 

Introduction

Styleclass
ClasstopLink

top

In this tutorial, we will walk through setting up a Union sub query. A good way to think about Unions is - use them if you need to combine multiple fields into the one column, either from the same or different views or sources.

In this scenario our main report will have a list of invoicing figures by region, we will then use the Union query to display negative cost figures in the same column, and then add sub totals to see the total income for each region.

 

Master Query

The Master Query is going to include:

  1. Camp Region
  2. Calculated Field: "Invoiced" text label
  3. Sum Invoiced Amount

 

Union Query

The Union Query will include:

  1. Camp Region
  2. Calculated Field: "Cost" text label
  3. Calculated Field: Sum Cost * -1 (to convert the Cost figures to a negative value)

 

Create

Styleclass
ClasstopLink

top

Section
Column
width30%

1.  Start the Report creation process by using one of these methods:

 

    • Left Side Nav - open the left side navigation panel, click on Create, select the Report option

 

    • Top Right Button - click on the create button, select the Report option.

 

    • Toolbar - click on the Create link in the toolbar, select the Report option.


You will now see the New Report lightbox.

Column
width70%
Left Side Nav

Top Right

(with Left Side Navigation enabled)

Toolbar
Section
Column
width30%

2. Click on the Ski Team view in order to use the fields defined within it for creating the report.

3. You will now be taken to the Data step of the Report Builder.

Column
width70%

 

 

Master Query

Styleclass
ClasstopLink

top

Section
Column
width30%

4. Drag and drop the Camp Region dimension and Invoiced Amount metric into the Columns list.

Column
width70%

 

Label Field

To complete the master query, a label field is required. This will be used to identify the rows from the master query as "Invoiced" rows. There will be a similar calculation in the union query to identify rows as "Cost".

Section
Column
width30%

5. Click on the + to create a calculated field, in the bottom of the View Fields List panel.

Column
width70%

Section
Column
width30%

6. Set the Calculated Field Name to Label
Note: the name for this field can be anything, it will not change the way the union works if it's called something else.

7. Type Invoiced into the text box under the main calculation panel, as shown here, and click + Add to add it to the calculation.

Column
width70%

Section
Column
width30%

8. Click the Validate button to ensure your calculation is built correctly.

9. Click the Save button to complete your calculation.

Column
width70%

Section
Column
width30%

10. Drag the Label calculation to between the Camp Region and Sum Invoiced Amount fields in either the Columns list or Table Preview.

Column
width70%

 

Union Query

Styleclass
ClasstopLink

top

Create Union

Section
Column
width30%

11. Click on the + button in the Sub Query panel to the left of the Data step to add a Sub Query.

12. Set the Type to Union and Style to Basic.

13. Click Ok to set up the query.

Column
width70%

 

Calculations

To complete the union query, two calculations will be required;

  1. Label: this will be used to identify the rows from the union query as "Cost" rows. There will be a similar calculation in the master query to identify rows as "Invoiced".
  2. Cost: this will be used to convert the cost figure to a negative value. This will mean that when a sub total is added to the report, the cost amount will be subtracted from the invoiced amount.

 

Label

Section
Column
width30%

14. Click on the + to create a calculated field, in the bottom of the View Fields List panel.

Column
width70%

Section
Column
width30%

15. Set the Calculated Field Name to Label
Note: the name for this field can be anything, it will not change the way the union works if it's called something else.

16. Type Cost into the text box under the main calculation panel, as shown here, and click + Add to add it to the calculation.

17. Click the Validate button to ensure your calculation is built correctly.

18. Click the Save button to complete your calculation.

Column
width70%

 

Cost

Section
Column
width30%

19. Click on the + to create a calculated field, in the bottom of the View Fields List panel.

20. Set the Calculated Field Name to Cost
Note: the name for this field can be anything, it will not change the way the union works if it's called something else.

21. Click on the button.

22. Select the Camp Cost field from the Select Field drop down, and click + Add.

23. Close the bracket by clicking ).

24. Click the * button to multiply the field by a value.

25. Type -1 into the text entry field, and click + Add to put in your calculation.

26. Click the Validate button to ensure your calculation is built correctly.

27. Click the Save button to complete your calculation.

Column
width70%

 

Configure Union

Section
Column
width30%

28. Drag the Camp Region field into the Sub Query Fields list, directly next to the Camp Region field in the Master Query Fields list.

29. Drag the Label calculated field into the Sub Query Fields list, directly next to the Label field in the Master Query Fields list.

30. Drag the Cost calculated field into the Sub Query Fields list, directly next to the Sum Invoiced Amount field in the Master Query Fields list.

31. Change the name of the Sub Query to Cost and click Save to complete the Union.

Column
width70%

 

Edit Settings

Section
Column
width30%

32. If you need to make changes to your sub query setup at all, click the Edit Settings link.

Column
width70%

 

Formatting

Styleclass
ClasstopLink

top

Section
Column
width30%

33. Click on the Sun Invoiced Amount field's drop down list and apply a Sum Total

Column
width70%

Section
Column
width30%

34. Click on the Camp Region field's drop down list and select Format. You could also select the Column Formatting menu from the main navigation bar.

35. Enable the Suppress Duplicates option. This will make the final table easier to read, with the inclusion of sub totals.

Column
width70%

Section
Column
width30%

36. While still on the Camp Region field, open the Summary settings and enable the Sub Total option.

Column
width70%

Section
Column
width30%

37. While still in the Column Formatting menu, select the Sum Invoiced Amount field from the list on the left.

36. Set the name to Value.

Column
width70%

Section
Column
width30%

38. Close the menu.

Column
width70%

 

Save

Styleclass
ClasstopLink

top

Section
Column
width30%

39. Click Report > Save to activate your report.

Column
width70%

Section
Column
width30%

40. Set the Name of your report to Union Sub Query Tutorial.

41. Set the Description to This report was written using the Sub Query Tutorial.

42. Select Tutorial as the Category.

43. Select Training as the Sub Category.

44. Click Activate to finish.

Column
width70%

Section
Column
width30%

45. You now have an active Union Sub Query report.

Column
width70%

 

horizontalrule
Styleclass
ClasstopLink

top