Before you read through this example, make sure you review the "Setting Context Variables" section of this article for an explanation of context variables.

We are going to walk through a custom language example that utilizes the context variable feature. As a reminder, context variables is a function that can be referenced by other functions. In other words, it allows you to nest functions within other functions.

Objective: We shipping data and we want to know the product that had the largest positive variance and the product that had the largest negative variance between days we expected it to ship in and days it actually shipped in. In our sentence, we also want to call out the actual amount of days it took.

Before context variables, our custom bullet would only let us report on one measure at a time and therefore, we were unable to write about the actual amount of days it took to ship. Context variables now allow us to reference those other measures.

Requirements for this example:

1 Dimension - Product

3 Measures - Days to Ship Scheduled, Days to Ship Actual, Day Variance

Steps:

1. I'm going to start by turning off all sections except for our "Days to Ship Actual" section. We will be adding all our custom bullets in here.
2. Add a custom story item and select "Set context variables" from the menu
3. I'm going to create a context variable and call it "product with best variance" so that we can talk about the product that was most ahead of schedule. To do this we are going to use the "SortDescendingLabel" function with Measure = Day Variance and Rank = 1. If you wanted your custom bullet to talk about the second-best product by variance you'd select Rank = 2 and so on.
4. Next, add your first function "DimensionValueLabel" and select the context variable in the dropdown list for "Dimension Value". This will function will print the name of the product with the best variance.
5. After typing some relevant text, our next function is going to be "Value" and we are going to call out the # of days the product was scheduled to ship in.
• Measure = Sum(Days to Ship Scheduled)
• Dimension Value = product with best variance; the context variable
6. Next, we are going to call out how many days it actually shipped in by using another "Value" function

• Measure = Sum(Days to Ship Actual)
• Dimension Value = product with best variance; the context variable
7. Our last function is going to be another "Value" but we are now going to call out the # of days that it was ahead of schedule aka the "variance"

• Measure = Day Variance
• Dimension Value = product with best variance; the context variable
8. Now we are ready to hit Save and see the sentences evaluate in our narrative! As an extra step, you can add in a condition that will make sure the "Day Variance" # is > 0.

9. To create the bullet that calls out the product that was most behind schedule we can Copy this bullet but we will swap out our Context Variable function to use "SortAscending", change the name of the context variable, and update some of our custom language in the bullet.

10. After we save and close out of the edit modal, we have our two custom bullets calling out products that were most ahead and most behind schedule!