Selecting a specific country for comparison

In this section, we will learn how to create an expression to retrieve the sales amount of a specific country so that we can use this value to compare it against all other countries.

To start, we will add a Table visualization to the sheet, Table chart with dimension Country, and master measure Sales $.

Follow these steps to create the visualizations:

  1. Click on the 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 Table chart.
  3. Click on the Table chart, 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. Click on the Data heading in the properties panel to expand it.
  2. Find the Add column button, click on it, and choose Measure.
  3. Select Sales $ in the Measure section.
  4. Fix the measure Number formatting to show a number with two decimal places.
  5. Click on the Add column button again to add the second measure.
  6. Click on the fx button to open the expression editor, and then type the following expression for the new measure: sum({<Country={Brazil}>} SalesAmount).
  7. Click on the Apply button to close the expression editor and save the expression.
  8. In the Label of the measure, type Brazil Sales $.
  9. Fix the measure Number formatting to show a number with two decimal places.
  10. Click on the Done button to enter the visualization mode. The Table chart will look like this:

We can only see Brazil with its value. To create the calculation of the value on Brazil, the Sales $ column needs to be repeated along all other countries. We will fix this by adding the TOTAL qualifier, as follows:

  1. Click on the Edit button to enter the edit mode.
  2. Go to the properties panel and click on the Data heading to expand it.
  3. Find the Brazil Sales $ measure.
  4. Click on the fx button to open the expression editor, and then replace the  expressions with the following: sum(TOTAL {<Country={Brazil}>} SalesAmount).
  5. Click on the Apply button to close the expression editor and save the expression.
  6. Find the Totals function property in the measure, and then select None to not display a value in the total heading. The Table chart will look like this:

To create the comparison calculation, add another measure column:

  1. Click on the fx button to open the expression editor, and then replace the expressions with the following: Column(1)-Column(2).
  2. Click on the Apply button to close the expression editor and save the expression.
  3. In the Label of the measure, type Variance.
  4. Fix the measure Number formatting to show a number with two decimal places.
  5. Click on the Done button to enter the visualization mode. The Table chart will look like this:

We learned how to use a Set Analysis modifier, {<Country={Brazil}>}, in the sum() function to summarize sales only for Brazil, but the resulting value was only applied to a single row. To repeat the result on all the other rows in the table, we used the TOTAL qualifier to disregard the dimension. To calculate the variance between Sales $ and Brazil's Sales $, we used the Column() function to reuse the calculations already created in the first two measures of the table, so we don't need to repeat all the formulas again.

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

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