Count Number of Elements in a List

Hi,

Is it possible to return a count of the number of elements retrieved in a tm1-ui-element-list?

I’d like to use an MDX statement to retrieve a list of elements, find out how many elements are in the list and then use that value in a calculation.

Thanks,
David

Hi @anz.fin.all.mailbox,

The count should be accessible via the length property from the model as it is just returning a normal JS Array. So for example, if the model name you passed onto it is ng-model=“lists.accounts”, then the count should be accessible via:

<span>Total: {{lists.accounts.length}}</span>

Cheers!

Paul

1 Like

Exactly what I was looking for! Thanks so much @plim.

Cheers,
David

Hi @plim,

A related question: I’m using a named MDX to create a table with weeks on the columns and customers on the rows. Is there a way to count the number of non-zero values for any given column? E.g.:

Customer W01 W02 W03
customer-A 1 0 0
customer-B 0 2 0
customer-C 1 0 0
customer-D 2 0 0
customer-E 0 1 0
customer-F 0 0 1
Count 3 2 1

Due to the nature of the data and the structure of the cube a ConsolidatedCount function won’t return the correct result.

Thanks,
David

Hi @anz.fin.all.mailbox,

How are you retrieving the results? Iterating through them as an array should be one of the fastest way to go about it.

You can use the standard for-loop or one of the built in libraries in there, Lodash (in particular _.each() ) to iterate through them and store the consolidations for each group/column. There should also be lots of articles about iterating through arrays in the web.

If you have a consolidated value in the TM1 server, then a DBR would also workout.

Let us know how it goes.


Cheers,
Paul