Condition to filter data on a measure

Here, we will learn how to create a measure in a table visualization using a condition to show only the sales amount for orders shipped the next day of the order date.

We will add the visualization, Table chart with dimensions OrderID, ShippedDate, OrderDate, and measure with Sales Amount with the shipped date condition.

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 on the right-hand side of the sheet:

  1. Click on Add dimension and select OrderID in the Dimensions section.
  2. Add the OrderDate and ShippedDate fields as dimensions.
  3. Click on the Add Measure button.
  4. Click on the fx button to open the expression editor, and then type the following expression: sum(if(ShippedDate<=OrderDate+1,SalesAmount)).
  5. Click on the Apply button to close the expression editor and save the expression.
  6. In the Label of the measure, type Sales $.
  7. Fix the measure Number formatting to show a number with two decimal places.
  8. To remove rows with zero (that is, rows that don't match the date criteria), click on the Add-Ons heading in the properties panel.
  9. Click on the Data handling section to expand it.
  10. Clear the Include zero values property, as shown in the following screenshot:

  1. Click on the Done button.
  2. Clear all selections. The Table chart will look like this:

  1. Go to the properties panel.
  2. Click on the Appearance heading, and then click on the General section to expand it.
  3. Switch on the Show titles property if disabled.
  4. Click on the fx button to open the expression editor.
  5. Type the following expression: ='There are '&count(distinct if(ShippedDate<=OrderDate+1,OrderID))&' Orders delivered next day'.

The Table chart will look like this:

We have now learned how to create a table chart that only shows orders that meet the date criteria: ShippedDate on the next day of OrderDate.

The rows with no matching criteria have a zero value in the Sales $ column, so we cleared the Include zero values property to remove them.

We created a dynamic title to show how many orders match the criteria. We used the count() function on the OrderID field with the distinct clause to count orders without repeating values.

The finished sheet now looks like the following screenshot:

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

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