Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
jasmina_karcic
Creator III
Creator III

avg(aggr(sum(... issue

Hi everyone,

I have a table:

STANJA_CORP.png

I need to calculate average value (or mean) for these values in table, column 1.

I make one measure:

AVG(AGGR(FABS(SUM({$<DATUM={"<=31.5.2018",">=1.5.2018"}, IZVESTAJ={"MIS_COR"}, KLAS_KLIJENTA-={"1","2"}, BROJ_REDA={"1"}>}STANJE_KM/(1000))),DATUM))


I should get value: 262 141


But I am getting this value:

AVG.png

Any help, please?

Jasmina

8 Replies
petter
Partner - Champion III
Partner - Champion III

Do you have any 0 values that shouldn't be taken into consideration for the average calculations?

jasmina_karcic
Creator III
Creator III
Author

hmmm I am thinking where can be this....

But if i made aggr by DATE how is possible for null values

petter
Partner - Champion III
Partner - Champion III

Null values are not the same as 0 (zero) values.

null value is a non-existing value or a placeholder for that and will not be taken into consideration for an average.

A 0 values willl be counted as a value.

You could also have negative values in you underlying data - if what you are showing is multiple KMs per date...

If you want to be sure that you only count and handle valid KMs then

Sum( {<KM={">0"}>} KM)  and see if the table give the same numbers and total sum.

Likewise you can add this condition to your average calculation:

AVG(AGGR(FABS(SUM({$<STANJE_KM={">0"},DATUM={"<=31.5.2018",">=1.5.2018"}, IZVESTAJ={"MIS_COR"}, KLAS_KLIJENTA-={"1","2"}, BROJ_REDA={"1"}>}STANJE_KM/(1000))),DATUM))

jasmina_karcic
Creator III
Creator III
Author

doesn't work...gets result 0

jasmina_karcic
Creator III
Creator III
Author

If I put script:

AVG(AGGR(FABS(SUM({$<STANJE_KM={">0"},DATUM={"<=31.5.2018",">=1.5.2018"}, IZVESTAJ={"MIS_COR"}, KLAS_KLIJENTA-={"1","2"}, BROJ_REDA={"1"}>}STANJE_KM/(1000))),distinct DATUM))

I get 255 306....

But this still is not average value

jasmina_karcic
Creator III
Creator III
Author

Something in DATE is not okay.

If i put range from 1.1.2018 to 30.4.2018

or from 1.1.2018. to 31.5.2018

or other...not important, it gives the same result....

jasmina_karcic
Creator III
Creator III
Author

When I write

FABS(SUM({$<DATUM={"<=31.5.2018",">=1.5.2018"}, IZVESTAJ={"MIS_COR"}, KLAS_KLIJENTA-={"1","2"}, BROJ_REDA={"1"}>}STANJE_KM/(1000)))/

count(DATUM={"<=31.5.2018",">=1.5.2018"}, IZVESTAJ={"MIS_COR"}, KLAS_KLIJENTA-={"1","2"}, BROJ_REDA={"1"}>}distinct DATUM)



it works....:/

sunny_talwar

I think this might be a good read on this topic

Average – Which average?