what does item() and code() do in lessons 6/7?
trying to figure out what each element in CODE(ITEM('E2 Employees#')) does - i have read the documentation https://help.anaplan.com/41298b7a-e877-40e8-8cfa-8d7009d8686f-ITEM and https://help.anaplan.com/0e20099c-af47-4343-9ad9-3a20b580d2de-CODE
but still can't grasp the idea: what does item return? then what does code return from the output of item?
Best Answer
-
ITEM()
The ITEM() formula returns a list-formatted value that matches the format of the supplied parameter. In order to use it, the line item must Apply To the supplied parameter, and the result must be formatted as the same list.
In the example below, ITEM('P2 Products') returns a value formatted as P2 Products. Note that the highlighted values are identical.
When you look at the grid view, the result appears in the cell as the name of the list member. However, the value is NOT text-formatted, as you can see in the blueprint.
CODE()
CODE(), along with related functions PARENT() and NAME(), return special properties from the supplied list member in text format.
2
Answers
-
My confusion has to do with why the inner call to 'item' is necessary in the code line item formula. When you look at the regular view of the module you have the item names showing up along the columns just fine. So why can't you just use code('p2 products'), at which point the system would grab the column header and finds its code? I believe (correct me if I'm wrong) it has something to do with it being used as a dimension in the model, but the system obviously knows what specific list item belongs to each column since it displays it, so it seems unnecessary. Therefore I think I get the "when" to use the item command and the "how," but I would like to know the "why" in regards to requiring the extra command inside the code function.
0 -
From a practical standpoint, the answer to "why" is "because the documentation says so":
Argument
Data type
Description
Item
List or time period
The list item or time period to return the code of.
The syntax is expecting a list item or time period, and not a list name.
From a theoretical standpoint, remember that while formulas are defined at the line item level, all calculations are still done at the cell level; you need to provide clarity on which code you're trying to return.
If you conceptually explode out what the formula would look like at the cell level, you might see something like this:
CODE(ITEM('P2 Products')) =
[Cell 1] CODE(Nutzo Bar) = "P001"
[Cell 2] CODE(Raising the Bar) = "P002"
[Cell 3] CODE(Cookie Crumbs) = "P003"
…However, if your formula was written as you suggested, you might instead see something like this:
CODE('P2 Products') =
[Cell 1] CODE('P2 Products') = ??? [Cell 2] CODE('P2 Products') = ??? [Cell 3] CODE('P2 Products') = ??? …
The individual cells would not be able to know what to get the code of.
Also remember the the CODE() formula is not always used to calculate the code of one of the line item's dimensions. It be used to return the code of any item supplied as a parameter. For example, you can do something like this:
In this case, it wouldn't be very meaningful to have a formula like the below:
CODE('Component SKU') & "_" & CODE('C2 Countries')
Anaplan wouldn't know which code from the Component SKU list to actually use.
Ultimately, I suspect this came down to a design choice by the original engine creators around making the syntax for CODE() to be flexible to handle different items as parameters. Note that there are no "overloaded" function definitions in Anaplan, which is why we don't have a CODE() formula that accepts either a list name or list item.
1