Skip to content

How to Create Computed field in Graphic Walker

islxyqwe edited this page Dec 28, 2023 · 2 revisions

This article describes how to create and use computed fields in Graphic walker using an example.

Why Use Computed Fields

Computed fields allow you to create new data from data that already exists. When you create a computed field, you are essentially creating a new field in your data source, the values or members of which are determined by a calculation that you control. This new computed field is saved in the chart, and your original data remains untouched.

You can use computed fields for many, many reasons.

  • To segment data
  • To convert the data type of a field, such as converting a string to a date.
  • To aggregate data
  • To calculate ratios

Create a computed field

  1. Click the "Add computed field" button in toolbar

image

  1. In the dialog, do the following:
  • Enter a name for the computed field. In this example, the field is called Discount Ratio.
  • Enter the sql expression for the computed field. This example uses the following expression: case when full_price_in_eur > 0 then discounted_price_in_eur / full_price_in_eur else 0 end this expression check whether the price is zero or not, and returns the discount ratio if full_price_in_eur is not zero, otherwises returns zero.

image

  1. When finished, click Add. The new field is added to measure field because it returns a number.

image

Use a computed field in the view

  1. Drag the "Discount Ratio" field into X-axis.
  2. Drag the "Category 1" field into Y-axis.
  3. Click the "sum" dropdown on the "Discount Ratio" field in X-axis, and select "mean".
  4. Click the "Sort in Ascending Order" button in the toolbar.

image