Harmoni allows you to create new items or customized constructions to suit your analysis and reporting requirements. New variables can be created using items that already exist in the project, or with user-entered values.

You can create a new item by first selecting the desired position in the project tree and then choosing one of the options under **construct **from the **design menu. Learn more about the design menu.**

Constructions can use items in one or many sources. Once created, constructions are automatically updated when new sources are added.

**In this article**

- Expression Editor
- Expression Editor Operators
- Expression Editor Conditions and Functions

- Save and Apply Expression

**1. Expression Editor**

The expression editor is the interface by which the new item definition is entered. The expression editor supports both ** typing** and

**to build the expression.**

*drag and drop***When typing:**

- The possible options are displayed for selection. Use the
to highlight the option choice, and**arrow down key**to select it.**Enter** - Existing elements in the dictionary are used in the definition.
- The possible matches are only displayed when they are similar, not identical.
- The most reliable way of including an item in a complex definition is through typing to display the list of matching labels, then selecting them from the displayed list.

### **When dragging:**

- An element can be defined using a single
condition by dragging a single element into the expression editor.**Axis.Element** - Dragging in more than one element from the same axis into the definition assumes an
across elements*or relationship* - Dragging in elements from different axes into the definition assumes an
*and relationship*

When an expression is saved the quotes may be stripped (they’re only required when the label contains special characters such as commas, brackets. etc.)

**2. Expression Editor Operators**

**a) Boolean logic operators**

**And**

decreases the number of data records included.**And**- Both conditions in an
relationship must exist in at least one source, or no records will be included in the construction.**and**

**Or**

increases the number of data records included.*Or*- Not all conditions in an
**or**relationship need to exist in any one source for records to be included in the construction.

**Not**

is to be used with either*Not*or an*and**or**operator.*- The definition after
must include the axis name before the element name.**not**

**AxisName.("(ElementName1)" or "(ElementName2)") and not Axis_Name."(ElementName3)" **

**Brackets**

are used to determine the order of calculation.*Brackets*

**Example**

Let's assume you want to create a new *"Target Segments"* axis with the following element:

= Females who visited a beach and a marine park/reserve, but didn't visit a geothermal park, glacier, national park, or hot pools.*Coast Focused Females*

In this case, you have a combination of standard axes and elements with a series of boolean operators.

*AxisName1.ElementName1 and AxisName2.ElementName1 and not AxisName3.ElementName1... *

**b) Comparative operators**

Comparative operators need to be associated with a numerical value. This value can come from a measure or defined by using the count function.

Comparative operators include:

- Greater than >
- Less than <
- Less or equal <=
- Greater or equal >=
- Not equal <>
- Equal =

**Example**

Let's assume you want to create a new *"Target Segments"* axis with the following element:

= 65+ years who visited the moon more than twice.*Frequent Flyer Retirees*

Here you have a combination of a standard axis and a measure. Given that you have a measure, you need to use a comparative operator to be associated with a numerical value, in this case, more than two visits.

*AxisName1.(ElementName1 or ElementName2 or ElementName3) and MeasureName1 **>** value *

**3. Conditions and Functions**

**a) If statements**

If statements are used to populate a new measure or weight with a different value depending on specific conditions.

**If statement syntax**

- The syntax for the if statement is:

*if (Logic_Test, Value_if_True, Value_if_False)*

- The syntax for a nested if statement is:

* if (Logic_Test, Value_if_True, if (Logic_Test, Value_if_True, Value_if_False))*

**Example**

Let's assume you want to weight Males and Females to a 50/50 distribution. Across all sources, the Male/Female distribution is 45/55. To change this to 50/50 we need to assign all males a weight of 1.111 (50/45) and all females need a weight of 0.909 (50/55). For any missing cases (i.e. No answer for Male or Female/ Value if False) we are assigning a NULL.

**b) Count responses**

The count function is used to **define a new element or a new measure **by counting the number of responses given to the items listed in a comma-separated list. The count function creates a **numeric value** from an existing axis, element or measure.

The numeric value generated from a count function can either be used in a new measure, or it can be compared to another value in order to create a True/False result for use in a new element.

*Axis*item(s) in the Count function count the number of elements in those axes that each respondent has a response in.- Individual
*Axis.Element*item(s) in the Count function will only ever generate a value of 0 or 1, as each respondent can only have a response to a specific element. - Each
*Measure*item in the count function will only ever generate a value of 0 or 1, as each respondent can only have one numerical response to a measure. - To sum multiple items together, list them within the Count function using a comma separator.
- Boolean operators can be used to specify relationships that must exist in order for a count to be included.

**Count function syntax**

**a) Counting all responses in a standard axis.**

With this syntax, the values count returns are the number of elements each respondent responded to. Note, only multiple-response variables will ever give a count greater than 1.

- Element:
*count (AxisName1) >= 1* - Measure:
*count (AxisName1)*

**b) Count function with Boolean logic can be used to count whether a respondent mentioned at least one response to a specific set of items.**

**Using count ( _ or _ or _ )**

With this syntax, the values count returns are 0 and 1. The maximum count the expression returns is 1.

- Element:
*count (AxisName1.(ElementName1 or ElementName2 or Element 3)) = 1* - Measure:
*count (AxisName1.(ElementName1 or ElementName2 or Element 3))*

**Using count ( _ , _ , _ )**

With this syntax, you can sum together counts from a specific set of items. It evaluates the number of items a respondent has answered and adds the count for each. The maximum count the expression returns is the max number of possible responses.

- Element:
*count (AxisName1.ElementName1*__,__AxisName1.ElementName2 , AxisName1.ElementName3)) = 3 - Measure:
*count (AxisName1.ElementName1*__,__AxisName1.ElementName2 , AxisName1.ElementName3)

**Examples**

Let's look at some examples. Let's assume you want to find out the number of devices that were used during a trip.

Element

In this case, you want to know how many respondents used one device, how many two, etc.

In order to avoid including the **None of these** item in the count, the best syntax to use for this scenario is **count ( _ , _ , _ ).**

Measure

To exclude the responses for the element "*None of these"* the best syntax to use is count** ( _ , _ , _ ). **This will just take into account the elements you want to include in the calculation.

Using the syntax ** count (AxisName1) **would consider all elements.

**c) Arithmetic calculations**

Arithmetic calculations need to be associated with a numerical value. This value can come from a measure or defined by using the count function.

Calculations in Harmoni include:

- Addition using +
- Subtraction using -
- Multiplication using *
- Division using /

**Example**

Let's assume you want to create an "*Other Costs"* measure containing the amount spent that wasn’t on airfares or packages, i.e. the amount left after subtracting airfares and packages from total spend.

**4. Save and Apply Expression**

Once you have defined your new items in the expression editor * Save Expression* and

*will become active. This will only happen when Harmoni validates the conditions you have entered.*

**Apply Expression*** Save Expression *will save your definitions but won't update data. To improve the workflow and efficiency when creating your custom variables, you can save your definitions as you go but only apply when you are ready.

When an expression is saved the * quotes* may be stripped (they’re only really required when the label contains special characters such as brackets).

Data is only updated in new items when ** Apply Expression** is applied to the axis.

* Save Expression* allows you to modify multiple expressions by delaying the data parse until you choose to apply. This gives the ability to control the actual moment that it gets applied.

**Where to from here?**

Learn more about different construction types.