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: 
anthony_kinsell
Creator
Creator

Avg function

Hi,

Just wondering can anyone clarify how this function actually works - to me it seems to calculate correctly sometimes & other times not - see table below:

UnitDescYearMonthJan-2013Feb-2013Mar-2013Apr-2013
Apartment 1 1,3001,3001,3001,300
Apartment 12 1,3001,3001,3001,300
Apartment 23 1,3004501,3501,350
Apartment 34 1,3001,3001,300641
Apartment 45 1,3001,3001,3001,300
Total 1,3009361,3101,089

Jan & Mar are correct but Feb & Apr aren't - expression is a simple Avg(Amount)

5 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     The difference may be because you might have some records for the month of Feb and Apr where Amount field has null values, so the avg will take the avg of all the records, and may be thus total is not correct.

     Try this function.

     sum(aggr(avg(Amount),UnitDesc,YearMonth)

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
anthony_kinsell
Creator
Creator
Author

Hi,

I had just realised that. I did a less sophisticated formula - but probable has the same result:

Sum(Amount) / Count(DISTINCT(UnitDesc))

Cheers

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

then you can try this.

Sum(Aggr((Sum(Amount)/Count(Distinct UnitDesc)),UnitDesc,YearMonth)

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
Not applicable

Hi,

Another possible way, make average without nulls with set analysis: Avg({<Amount={'*'}>} Amount)

anthony_kinsell
Creator
Creator
Author

Thanks Guys,

Think my simple formula works best in this case as the problem isn't null values it's numerous values in a given month for a given apartment - for example if an apartment has 4 values in 1 month I want the total of these but divided by 1 not 4. Also if an apartment has no value it should still reduce the overall average.

Regards

Anthony