Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
retko1985
Creator II
Creator II

Average of Amount over the selected Year, but previous Year has null in the Amount field

Hello,

please refer to the attached file.I made the Inline data, where I have 2 Years, Months and Amounts. In 2016 the Amounts are NULL.

I want to make an average, of the Amount when 2 Years are selected, but this does not work now:

sum(Amount1) / (12 * GetSelectedCount(Year))

I got number 5, when 2 Years are selected, but should be 10.

Next Year I will have data for this Amount for both Years.

I cannot use AVG!, because of nested aggregation, since I already do sum (so this example is not precise)

Can you please suggest better expression?

Thank you.

1 Solution

Accepted Solutions
tresesco
MVP
MVP

If you have real nulls in the data, you could try like:

=sum(Amount1) /(12 * Count(DISTINCT {<Amount1={'*'}>}Year))

If not really nulls but no amount (some other values like, space or other invisible characters), try like:

=sum(Amount1) /(12 * Count(DISTINCT {<Amount1={"=Len(Trim(Amount1))>0"}>}Year))

View solution in original post

6 Replies
prat1507
Specialist
Specialist

Maybe this

=avg(Aggr(Sum(Amount1),Year,Month))

Regards

Pratyush

sunny_talwar

You can also try this

=Sum(Amount1)/Count(DISTINCT Year&Month)

tresesco
MVP
MVP

If you have real nulls in the data, you could try like:

=sum(Amount1) /(12 * Count(DISTINCT {<Amount1={'*'}>}Year))

If not really nulls but no amount (some other values like, space or other invisible characters), try like:

=sum(Amount1) /(12 * Count(DISTINCT {<Amount1={"=Len(Trim(Amount1))>0"}>}Year))

retko1985
Creator II
Creator II
Author

still gives 5 in model example and doesnt work on my app.

prat1507
Specialist
Specialist

Ok, so what is it evaluating in your app?

Regards
Pratyush

retko1985
Creator II
Creator II
Author

Perfect, Thank you.