Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Bobby_Nguyen
Contributor
Contributor

What's wrong with the average function?

Can somebody help me with this please:

I've bumped into this problem while i was trying to calculate the average of sum sales in Sep

+ with the sum/count date : sum({<DateCode={">=$(vPresentMonth) <=$(vPMonthEnd)"}>} NoOfOrders)/count({<DateCode={">=$(vPresentMonth) <=$(vPMonthEnd)"}>} distinct DateCode)--> get the exact value compare to my caculator

+with the avg(): avg(aggr(sum({<DateCode={">=$(vPresentMonth) <=$(vPMonthEnd)"}>} NoOfOrders),DateCode))--> a wrong number 

here's the thing: I found that there's only 6 days that the sum(sales) is divided by, but avg() divided it by 7 instead of 6.Can somebody explain me this?

I would be so appreciate for your help with this!!!!

Picture attached below.

 

 

Labels (1)
2 Replies
marcus_sommer

There is probably nothing wrong with the avg() else it will be a matter of your datamodel and/or the data-quality. Maybe there are any missing values or NULL's within the data or DateCode might be key field ... I could imagine that it may display your expected value if you add the condition to the outer aggregation, too:

avg({<DateCode={">=$(vPresentMonth) <=$(vPMonthEnd)"}>}
    aggr(sum({<DateCode={">=$(vPresentMonth) <=$(vPMonthEnd)"}>} NoOfOrders),
DateCode))

- Marcus

Bobby_Nguyen
Contributor
Contributor
Author

Thanks very much Marcus, I really appreciate it.

I'll check again my data-modeling and quality of data.