Insights visual narrative: dynamic indexing into Top.items[] supported?

I’m building a narrative template that uses “Top ranked” computation (Top.items[index].metricValue.value, Top.itemsCount). I need the “last element” regardless of length, but array access requires a literal index and rejects itemsCount - 1.

Is dynamic indexing intentionally unsupported in narratives? If yes, what workaround is considered best practice?

Hi @Alex_Feldman!

Thanks for your patience on a reply. Many of our Experts are OOO this week due to US holidays. I asked “My Assistant” in Quick Suite and got this answer (which will need to be validated) to your question:

"Current Limitation:

Dynamic indexing into arrays like Top.items[] is not currently supported in QuickSight narrative templates. The narrative expression editor requires literal index values and does not accept computed expressions like itemsCount - 1 for array access.

Why This Limitation Exists:

The narrative template system uses a specific expression language that evaluates array indices at template compilation time rather than runtime. This means you cannot use variables or calculations to dynamically determine which array element to access.

Recommended Workarounds:

  1. Use a fixed high index: If you know the maximum possible number of items, you can reference a specific index like Top.items for the 10th item, though this won’t adapt to varying result counts.
  • Create multiple conditional statements: Use conditional logic to handle different array lengths, though this becomes cumbersome:
{if Top.itemsCount == 5}
  {Top.items.metricValue.value}
{elseif Top.itemsCount == 4}
  {Top.items.metricValue.value}
...
  • Customize the computation: Instead of using “Top ranked” computation, consider creating a custom calculation at the dataset level that identifies the last element before it reaches the narrative template.
  • Feature request: This appears to be an intentional design limitation rather than a bug. I’d recommend submitting this as a feature request through AWS Support or the QuickSight community forum, as dynamic array indexing would be a valuable enhancement for flexible narrative templates."

I have marked this as a feature request.

@drpeter @WLS-Luis or @WLS-JD Please validate and/or add additional reply when back in the from the holidays next week. Thanks!

1 Like

Thank you for the update, Kristin!

One quick clarification from my side after testing:

  • Using an expression like
    ifelse(Top.itemsCount = 3, Top.items[2].metricValue.value, Top.items[1].metricValue.value)
    did not work for me, because it still attempts to evaluate Top.items[2] even when the condition is false (so it errors when the array has only 2 items).

  • The Inline IF block approach does work as expected, because it only evaluates the expression inside the block when the condition is true. I implemented two Inline IF blocks (for itemsCount = 2 and itemsCount = 3) and that solved the “last item” requirement.

Given that, I don’t think this needs a feature request on my end anymore. I was able to handle the issue with Inline IF. Thanks!

1 Like

Another quick thought reading through your query, if you use bottom ranked instead of top and instead of dynamic index use 1, that may fetch the same result.

1 Like

Thanks for the update @Alex_Feldman. And thanks for the additional feedback @prantika_sinha ! :slight_smile: