Best Practice: PARENT() vs. LOOKUP ?

I am looking for assistance to understand best practice/performance implications between 2 different approaches of getting a list item parent in a formula. Imagine I have 3 modules: X, Z, and System Module. The System Module contains Parent line item with formula PARENT(PARENT(ITEM('List Items'))). I want to return this same parent item in a new module and line item and I can use either method 1 or 2:

Method 1: PARENT(PARENT('Module Z'.'Child Line Item'))

Method 2: 'System Module'.'Parent'[LOOKUP: 'Module X'.'Child Line Item']

Is it better to use Method 2 as it follows the idea of "calculate once, refer to many times" , or is it better to use Method 1? Curious how the engine evaluates the parent() function and nested parent() functions.

Best Answers

  • vishal3120
    edited September 2023 Answer ✓

    I guess you yourself gave the answer to your query at last. Still if I elaborate a little, in method 1: everytime that line item would be used it would have to first look into the list then find the parent of it and then engine will run again to calculate the parent of the parent.

    But in method 2: You have a system module which has already done all the calculations and this time engine has to just refer the value(Parent) from system module and place it accordingly. Therefore, load on engine in method 1 »»» method 2.

    PS: Anaplan engine is way too fast that you won't feel any difference after using either of Method 1 or Method 2 ;)

  • @vishal3120 @Zak_G

    You should never use parent(parent(item)) even in the SYS module. In the SYS module, break it up so it is this:

    item: item(list)
    parent: parent(item)
    grandparent: parent(parent)

    And yes, there is a performance difference, it is better to do the calculation once (in the SYS Module) and reference it in other modules than doing the same calculation in multiple modules.

Answers

  • vishal3120 - thank you for your comment and indeed, in retrospect, I think I was probably overthinking things … I was concerned that using Method 2 would leave me open to daisy chaining , but as long as I remember to reference the system module instead of one of the line items looking up this value, I should be in the clear. Thank you!