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

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
kunkumnaveen
Specialist
Specialist

How to write an expression for below requirement

Hello All,

I need to design a bar graph with Dimension (B_Mode)and with a expression which accumulate last three months  avg(Count_Br ) excluding the selected month 

For Example :i have max data till 2019 Oct.

if no month and year is selected it has to  then take the avg of past three months(Sep,Avg,Jul)

if any month is selected (2019,Feb) then it should take avg of  the past three months(2019Jan,2018Dec,2018,Nov)..

Chart:Bar Chart

Dimension: B_Mode

Expression: Avg({   ?   }Count_Br)

 

Thank

 

Please find the attached sample data...

 

21 Replies
kunkumnaveen
Specialist
Specialist
Author

Hi  Thanks a lot man its working ,

just need a small suggestion from you, i am trying to do sum of count_BR of three past months and then avg of that sum of past three month.

i tried below below expression but having some miss fire .

avg(
{<Year,M_Month, Date = {">=$(=monthstart(addmonths(max(Date),-3)))<=$(=monthend(addmonths(max(Date),-1)))"}>}
aggr(Sum({<Year,M_Month, Date = {">=$(=monthstart(addmonths(max(Date),-3)))<=$(=monthend(addmonths(max(Date),-1)))"}>}Count_Br),B_Mode))

what am i missing 

 

Kushal_Chawda

this should work

=alt(avg({<Year,M_Month, Date = {">=$(=monthstart(addmonths(max(Date),-3)))<=$(=monthend(addmonths(max(Date),-1)))"}>}
aggr(sum({<Year,M_Month, Date = {">=$(=monthstart(addmonths(max(Date),-3)))<=$(=monthend(addmonths(max(Date),-1)))"}>}Count_Br), 
Year, M_Month)
),0)