Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

count / sum Problem

Hi

sorry ... but i need help

hi had this function - works very well:

count({< MA_BAUREIHE = {'ELION','ELION_HYBRID','EVOS'} >}   distinct BI_VERTRIEBSBELEG_NR&BI_VERKAUFSBELEG_POS )

but now i have to add a filed with quantity: BI_MENGE. It means my count value * BI_MENGE.

I tried al lot off different things ... but nothing is working

Aggr(DISTINCT BI_VERTRIEBSBELEG_NR&BI_VERKAUFSBELEG_POS, sum (BI_MENGE ))

.....

please help

1 Solution

Accepted Solutions
swuehl
MVP
MVP

I think we are getting closer. Your expression could probably look like

=sum(aggr(FirstSortedValue(BI_MENGE,- KEY_LAUFDATUM_DATUM),BI_VERTRIEBSBELEG_NR))

This assumes that BELEG_NR is a valid dimension here in your case (in your sample, POS_NR was always identical).

But in case you need the POS_NR, I think you need to create a field in your script defining your distinct dimension (you can't use a calculated dimension in the aggr() function, unfortunately) and then use this field as aggr() dimension.

See also attached.

Stefan

View solution in original post

9 Replies
swuehl
MVP
MVP

We probably need to know where / in which context you are using this expression (this might include needing to know a bit about your data model).

In a very simple case, you could try something like

=count({< MA_BAUREIHE = {'ELION','ELION_HYBRID','EVOS'} >}   distinct BI_VERTRIEBSBELEG_NR&BI_VERKAUFSBELEG_POS )

* sum(BI_MENGE)

Not applicable
Author

Hi

no ... your formula give me a wrong result ... match to high

what you must now about my data model ?

swuehl
MVP
MVP

It's probably easiest if you could post a small sample (app or xls or inline data) to the forum, together with your expected outcome.

Do you want to calculate the expression in a chart (with what dimensions?) or in a text object?

How are the fields involved connected to each other?

Not applicable
Author

it a chart.

the formula creats the vaules you can see.

for example the last one 142 -> count({< MA_BAUREIHE = {'ELION','ELION_HYBRID','EVOS'} >}   distinct BI_VERTRIEBSBELEG_NR&BI_VERKAUFSBELEG_POS )

dia.jpg

the data looks like this:

dia2.jpg

but now i have 1 dimenson more BI_MENGE

swuehl
MVP
MVP

I assume you are using one dimension right now, a Date dimension, right?

Since you are doing a distinct count of BELEG_NR & BELEG_POS, I also assume that you could have multiple occurences of the same BELEG_NR & BELEG_POS on a single day, is this correct?

If so, could you also have different BI_MENGE for these records with identical BELEG_NR & BELEG_POS?

And how do you want to use the BI_MENGE then in your calculation? I am still missing an example with your expected outcome.

Not applicable
Author

swuehl schrieb:

I assume you are using one dimension right now, a Date dimension, right?

--> yes

Since you are doing a distinct count of BELEG_NR & BELEG_POS, I also assume that you could have multiple occurences of the same BELEG_NR & BELEG_POS on a single day, is this correct?

--> not a single day - but the same records over different months

If so, could you also have different BI_MENGE for these records with identical BELEG_NR & BELEG_POS?

And how do you want to use the BI_MENGE then in your calculation? I am still missing an example with your expected outcome.

--> yes the bi_menge can be different and shod be taken from the last run_date

please have a look in to my test.qvw.

thanks alot for your effort !

ben

swuehl
MVP
MVP

I think we are getting closer. Your expression could probably look like

=sum(aggr(FirstSortedValue(BI_MENGE,- KEY_LAUFDATUM_DATUM),BI_VERTRIEBSBELEG_NR))

This assumes that BELEG_NR is a valid dimension here in your case (in your sample, POS_NR was always identical).

But in case you need the POS_NR, I think you need to create a field in your script defining your distinct dimension (you can't use a calculated dimension in the aggr() function, unfortunately) and then use this field as aggr() dimension.

See also attached.

Stefan

Not applicable
Author

thats looking really well !

I need the POS_NR - it's not always 0100. i will make a new field with BELEG_NR & POS_NR.

I am back tomorrow

thanks al lot


Not applicable
Author

Hi Stefan

Now it's working nice !

Thanks a lot for your Help !

Regards

Beny