Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

getting the sum of rows in an aggregate

Hi there,

I have the following expression to use in a variable:

count(aggr([Startdate Inspection], [MutationID]))

This gives me the same "expression total" result when I create a straight table with MutationID (Supress When Value is Null is ON, due to how my data model is built) as my dimension and count([Startdate Inspection]) as my expression.

However, I need to get the "sum of rows", because sometimes a Mutation has an inspection twice.

I cannot recreate the "sum of rows" in the aggregate expression. I have tried all kinds of stuff. When i start using sum() around my aggregate it gives me a number that is way to high.

Sorry in advance: i cannot share my qvw due to confidentiality reasons...

Anyone with any ideas?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Seems like

sum(aggr(Count([Startdate inspection]) , [MutationID]))

is what you need.

But you may need to add a set expression to filter on MutationID that are not NULL

sum({<MutationID = {"*"}>} aggr(Count({<MutationID = {"*"}>}[Startdate inspection]) , [MutationID]))

View solution in original post

7 Replies
effinty2112
Master
Master

Hi Kevin,

Maybe

Count(DISTINCT MutationID)

is all you need.

or  perhaps

Count({$<[Startdate Inspection] = {'*'}>}DISTINCT MutationID)


Good luck


Andrew

Not applicable
Author

Hi Andrew,

Thanks for the suggestion with the wildcard character, did not think of that.

However, it is not the solution. Sadly

swuehl
MVP
MVP

Could you post some sample lines of records and your expected result?

It's unclear how I should read "However, I need to get the 'sum of rows', because sometimes a Mutation has an inspection twice"

Maybe

Sum( Aggr(  Count([Startdate Inspection]), [MutationID]))

pradosh_thakur
Master II
Master II

its still unclear but if i understood you correctly

you should try

sum(aggr(count([Startdate Inspection]), distinct [MutationID])) instaed of   count(aggr([Startdate Inspection], [MutationID]))

or may be

Count({1}[Startdate Inspection]) will give you total no of INSPECTION.

if want the sum of rows in the table itself you can use rangesum with above and rowno()

so kindly elaborate your issue .

regards

Pradosh

Learning never stops.
Not applicable
Author

Hi, sorry for not being clear enough.

A sample: 12 is the result I weant (totals on first row)

 

MutationIDcount([Startdate inspection])sum(aggr(Count([Startdate inspection]) , [MutationID]))
20012
MUT00000111
MUT00000511
MUT00000811
MUT00000911
MUT00001022
MUT00001122
MUT00001211
MUT00001311
MUT00001411
MUT00001711
-1900

count([Startdate inspection] will give me as Expression total 200, while sum of rows gives 202.

When i set Supress When Value is Null I end up with:

MutationIDcount([Startdate inspection])sum(aggr(Count([Startdate inspection]) , [MutationID]))
1012
MUT00000111
MUT00000511
MUT00000811
MUT00000911
MUT00001022
MUT00001122
MUT00001211
MUT00001311
MUT00001411
MUT00001711

count([Startdate inspection] will give me as Expression total 10, while sum of rows gives 12.


When i use the second expression in a variable I end up with a different result! Which is 202


The use of {1} or {$} does not seem to affect my results.


The use of "distinct" gives either an error or 0


PS: the variable is in a Text object: =$(vTile04Measure).

The expression in the variable is without an equal sign: sum(aggr(Count([Startdate inspection]) , [MutationID]))

swuehl
MVP
MVP

Seems like

sum(aggr(Count([Startdate inspection]) , [MutationID]))

is what you need.

But you may need to add a set expression to filter on MutationID that are not NULL

sum({<MutationID = {"*"}>} aggr(Count({<MutationID = {"*"}>}[Startdate inspection]) , [MutationID]))

Not applicable
Author

That last epxression did it! Thanks a lot! This function within an expression will also be extremely helpful to me in future projects