# Lesson 7: Define a Conditional Field – Year-on-Year Comparison

In this lesson, we will analyze the meal expenses over a two-year period by person.

## Create New Report

Right-click on the Expense Analysis (Line Item/Matter) object and select NEW > REPORT.

• Add the following column to the report as dimensions (BY):
• Header (Segment) - Owner (Segment) – Expense Owner (Field)
• Header (Segment) - LineItem (Segment) – LineItemType (Segment) - Expense (Field)
• Add the following column to the report as measure (SUM):
• Header (Segment) - LineItem (Segment) – LineItem_Matter (Segment) - Amount (Field)

## Create a Billable/Non-Billable Field

1. In the Quick Access Toolbar, in the Data tab, in the Calculation group, click on Detail (Define).
2. Change the Field name to Billable.
3. Click on the Format button.
4. Change the Field type to Alphanumeric and the Total length to 12.
5. Click OK in the Field Format Options for (Billable) window. Do NOT close the Detail Field (DEFINE) window.

## Enter the IF Condition

1. Using the calculator-style buttons in the Detail Field (DEFINE) window, select the IF button.
2. Using the Tree View on the right, double-click on Header (segment) - LineItem (Segment) - LineItem_Matter (Segment) – Matter (Segment) – IsBillable (field).
3. Using the calculator-style buttons, select the = button.
4. Using the calculator-style buttons or keyboard, enter 1.
5. Using the calculator-style buttons, select the THEN button.
6. Enter 'Billable' (make sure it is enclosed in single quotation marks).
7. Using the calculator-style buttons, select the ELSE button.
8. Enter 'Nonbillable' (make sure it is enclosed in single quote marks). The field should read:

IF HEADERLINEITEMMATTER.Matter.ISBILLABLE EQ 1 THEN 'Billable' ELSE 'Nonbillable'

1. Click OK in the Detail Field (DEFINE) window.

## Create a Prompt Filter for the New Billable Field

1. The new Billable field should be at the end of Header (Segment) - LineItem (Segment) - LineItem_Matter (Segment) – Matter (Segment). Add the field as a Measure (SUM).
2. Right-click on the Billable field in the Query Pane. Select Filter Values.
3. Double-click on < Value > and select Parameter for the Type.
4. For the Name, enter Billable. For the Description, enter Matter Type: Note: Names are case-sensitive.
5. Click the STATIC button.
6. Check the Select Multiple Values at Runtime box.
7. Click GET VALUES and select ALL.
8. Select Billable from the list and click the blue double-arrow icon to add it to the box on the right. Do the same for Nonbillable.
9. Click OK to close the window.

## Create a Field for the Value of Expenses in 2014

1. In the Quick Access Toolbar, in the Data tab, in the Calculation group, click on Detail (Define).
2. Change the Field name to Year2014.
3. Using the calculator-style buttons, select the IF button.
4. Using the Tree View on the right, double-click on Header (segment) - LineItem (Segment) – Transaction Year (field).
5. Using the calculator-style buttons, select the = button.
6. Using the calculator-style buttons, enter 2014.
7. Using the calculator-style buttons, select the THEN button.
8. Using the Tree View on the right, double-click on Header (segment) - LineItem (Segment) – LineItem_Matter (Segment) – Amount (field).
9. Using the calculator-style buttons, select the ELSE button.
10. Using the calculator-style buttons, enter 0. The field should read: IF HEADERLINEMATTER.LineItem.TransactionYear EQ 2014 THEN HEADERLINEMATTER.LineItem_Matter.AMOUNTSPENTCONVERTED ELSE 0
11. Copy (Ctrl + C) the IF Statement.
12. Click OK to close the Detail Field (DEFINE) window.
13. This field should be visible at the bottom of Header (segment) - LineItem (Segment) – LineItem_Matter (Segment). Add the field as a Measure (SUM).

## Create a Field for the Value of Expenses in 2015

1. In the Quick Access Toolbar, in the Data tab, in the Calculation group, click on Detail (Define).
2. Change the field name to Year2015.
3. Either repeat the procedure from the previous step, or paste in the entire IF condition from the previous step.
4. Change the year to 2015 inside the IF condition. The field should read: IF HEADERLINEMATTER.LineItem.TransactionYear EQ 2015 THEN HEADERLINEMATTER.LineItem_Matter.AMOUNTSPENTCONVERTED ELSE 0
5. Click OK to close the Detail Field (DEFINE) window.
6. This field should be visible at the bottom of Header (segment) - LineItem (Segment) – LineItem_Matter (Segment). Add the field as a Measure (SUM).

## Create a Field for the Difference between Year2014 and Year2015

1. In the Quick Access Toolbar, in the Data tab, in the Calculation group, click on Detail (Define).
2. Change the field name to YearDiff.
3. Double click on Header (segment) - LineItem (Segment) – LineItem_Matter (Segment) – Year2015 (field).
4. Using the calculator-style buttons, select the (minus) button.
5. Double click on Header (segment) - LineItem (Segment) – LineItem_Matter (Segment) – Year2014 (field).
6. Click OK to close the Detail Field (DEFINE) window.
7. This field should be visible at the bottom of Header (segment) - LineItem (Segment) – LineItem_Matter (Segment). Add the field as a Measure (SUM) to verify the calculation.

## Hide Fields and Subtotal

1. If the YearDiff calculations are correct, right-click the Billable, Year2014, and Year2015 columns to change the Visibility to Hide.
2. Select the Expense Owner column.
3. On the Field – Expense Owner tab, in the Break group, select SUBTOTAL.

1. On the Home tab, in the Report group, in the Header & Footer drop-down menu, select Report Footer.
2. Delete "Enter Text here" and enter Selection: &Billable.
3. Click OK to close the Header & Footer window.

## Save and Run the Report

1. In the Quick Access Toolbar, click the Save button. Save the report in this location: Content > [Your Company Name] > My Content
2. Name the report “Lesson 7 – Defining a Conditional Field – Year on Year Comparisons."
4. Select the Matter Type Parameter.
5. Click Run.

<% if (allItems.length > 1) { %>

<% } %>
<% var getColumnClasses = function(numberColumns) { var classNames = 'col-12'; if (numberColumns >= 2) classNames += ' md:col-6'; if (numberColumns >= 3) classNames += ' lg:col-4'; if (numberColumns >= 4) classNames += ' xl:col-3'; return classNames; } %>

<% } %>
<% var getColumnClasses = function(numberColumns) { var classNames = 'col-12'; if (numberColumns >= 2) classNames += ' md:col-6'; if (numberColumns >= 3) classNames += ' lg:col-4'; if (numberColumns >= 4) classNames += ' xl:col-3'; return classNames; } %>

<% } %>
<% var maxSections = 5 %>
<% if (sections.length) { %>
<% sections.forEach(function(section) { %>
• <%= partial('partial-article-list-sections', { id: 'section-' + section.id, parentId: '#' + id, sections: section.sections, activeCategoryId: activeCategoryId, activeSectionId: activeSectionId, activeArticleId: activeArticleId, partial: partial }) %> <% if (section.articles.length) { %> <% } %>
• <% }); %>
<% } %>
<% if (sections.length) { %>
<% sections.slice(0, maxSections).forEach(function(section) { %>
• <%= section.name %> <%= partial('partial-section-list-sections', { parent: section, sections: section.sections, maxSections: maxSections, partial: partial }) %>
• <% }); %> <% if (sections.length > maxSections) { %>
• See more
• <% } %>
<% } %>
<% var getColumnClasses = function(numberColumns) { var classNames = numberColumns === 'auto' ? 'col-auto' : 'col-12'; if (numberColumns >= 2) classNames += ' md:col-6'; if (numberColumns >= 3) classNames += ' lg:col-4'; if (numberColumns >= 4) classNames += ' xl:col-3'; return classNames; } %>
<% blocks.forEach(function(block, index) { %>
• <% if (imageHeight) { %> <% } %>
<% if (block.name) { %>

<% if (block.html_url) { %> <%= block.name %> <% } else { %> <%= block.name %> <% } %>

<% } %> <% if (block.description) { %>

<%= block.description %>

<% } %>
• <% }) %>