Most efficient formula to count records

I want to include a total record count in the titles of a number of views. I plan to add a VC in each table needed (and add that to each slice) Whatโ€™s the least costly formula to count records (filter, select, count)? I donโ€™t want to hurt sync speed if I can avoid it. Thoughts appreciated.

Solved Solved
0 15 3,590
1 ACCEPTED SOLUTION

The exact error might be useful.

Spaces are fine, but I donโ€™t know about parentheses. I suspect the parens are confusing the expression parser, which likely sees activities(open), a function call, followed by [_rownumber], a column reference.

View solution in original post

15 REPLIES 15

I donโ€™t know for certain but, based on my limited experience, I would think that filter and select would tend to be more costly than count. Iโ€™m interested in the answer to this because Iโ€™m using โ€œcountโ€ in some virtual columns in my app to do this. Iโ€™m using

count(Slice name[Key])

In this case the slice has done what filter or select might do. Of course, if you donโ€™t have a slice and need to pick out a subset of records to count, I think used need to use filter or select.

Thanks @Kirk_Masden. On my case I used the following in the VC
COUNT(FILTER(Activities, IN([State], {"(1) OPEN", "(2) IN-PROGRESS","(3) PAUSED"})))

But then had to take the MAX of this column in the view to get a single number. I have to take another look because there is likely a simpler wayโ€ฆ

*My actual use case is, because the histogram chart cannot show the total record count it is based on (just shows the hover popup per bar), I want to modify the view title to shown count of the filtered record set. My approach was to add a VC, but am concerned that this has to be recalculated for every single record, each sync, rather than just when the chart view is accessed - so speed is a concern.

Other approaches appreciated!

@Mike why do you need to add the MAX for the number? The result from the COUNT expression is a number already?

Hi @Aleksi. I did this really quick last night, but without MAX, i was getting a count returned for each and every record - basically a list of counts, but all the same total count.

Looked like: 117, 117, 117, โ€ฆ

So, just did MAX so I got one number for count of all records. Before solving what I did wrong there, figured I would ask about the โ€œleast expensiveโ€ approach to getting a record count returned from a slice (which is actually all I want)โ€ฆ

You didnโ€™t make any mistakeโ€ฆ when you are calculating something with the virtual column, it calculates the formula for all records. IF the formula is very generic like COUNT(Table[Column]), the result is the same for all recordsโ€ฆ but still itโ€™s just one number.

Steve
Platinum 4
Platinum 4

Just perform the count in the viewโ€™s Display Name expression. I would most definitely not do it in a virtual column attached to each row of the table. Yikes!

As for the best formula, the fastest is likely to be a raw column reference (e.g., MyTable[_ROWNUMBER]). SELECT() and FILTER() are likely to be slower.

LOLโ€ฆ thanks @Steve! I thought a VC might be trouble.

When you say โ€œMyTable[_ROWNUMBER]โ€, can โ€œMyTableโ€ be a slice? I need that as the slice has a Row filter condition. I can get Activities[_ROWNUMBER] to work, but thatโ€™s the entire table.

What I really want to do is to use a slice named โ€œActivities (Open)โ€ as the source for COUNT like:
COUNT(Activities (Open)[_ROWNUMBER]) but that does not work (and quotes around slice name did not help).

Soโ€ฆ is there any way to use the slice name in the view Display Name expression? Or do I need to rebuild the entire slice condition into the view Display Name expression?

Current condition is: AND([State]<>"(4) Closed", [State]<>"(5) Canceled",[ID#]<>"undefined")

UPDATE: I deleted to VC and used the following in my view Display Name expression:

โ€œOpen Activities โ€œ&โ€(โ€&
COUNT(FILTER(Activities, IN([State], {"(1) OPEN", โ€œ(2) IN-PROGRESSโ€,"(3) PAUSED"})))
&")"

If anyone knows a better approach, feel free to chime in!
ps: disadvantage of this approach is, I need to maintain this formula both in the slice and the view. Not the most efficientโ€ฆ

Yep!

Hmmmโ€ฆ couldnโ€™t get that to work with slice name Activities (open). Forget the exact error but will re-check.

Tried:
Activities (open)[_ROWNUMBER]
โ€œActivities (open)โ€[_ROWNUMBER]
โ€˜Activities (open)โ€™[_ROWNUMBER]

Will have to try again. If the table name has spaces, does it need to be surrounded in quotes?

The exact error might be useful.

Spaces are fine, but I donโ€™t know about parentheses. I suspect the parens are confusing the expression parser, which likely sees activities(open), a function call, followed by [_rownumber], a column reference.

Using Activities (open)[_ROWNUMBER] as the chart view Display Name
results in the error of:
โ€œUnable to find function โ€˜ACTIVITIESโ€™, did you mean โ€˜INITIALSโ€™?โ€

Will rename my slice and report backโ€ฆ

Bingo!

CONCLUSION: never us parenthesis in Slice names!

COUNT(Activities (open)[_ROWNUMBER]) generates an โ€œUnable to find functionโ€ error.

COUNT(Activities_open[_ROWNUMBER]) works perfectly.

Heh.

Iโ€™ve reported this confusing behavior.

In what way didnโ€™t it work?

Top Labels in this Space