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

Announcements
April 13–15 - Dare to Unleash a New Professional You at Qlik Connect 2026: Register Now!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Last Week Median Calculation using aggr()

Dear All,

i have a Member Name Dimension and Date and WeekStartDate and Turnover and DealersCount

my requirement is to get Previous Week datewise Median Dealer count.

i have used below mention set analysis to get information :

Median(aggr(sum({<DATE1=,WEEKSTARTDATE={"$(=date(max(WEEKSTARTDATE)-7,'dd-MMM-yyyy'))"}>} DEALERCOUNT),NAME,DATE1 ))

when i am not selecting any DATE1 then its working fine, but when i select any DATE1, its did not give me the result.

Kindly help.

i am sending you attached excel and qvw for same.

note: my actual table have more dimension and columns.

thanks & Regards,

Jitendra Kumar Vishwakarma

7 Replies
avinashelite

Try like this , create week field in your script ( with the year column if required). then use this field in the front end calculation

week(date)

Week number. Returns an integer representing the week when the fraction of expr is interpreted as a date according to the standard number interpretation.

Example:

week( '1971-10-30' ) returns 43.

Not applicable
Author

Instead of Week Number i have already Stored WeekStartDate which is similar to that.

Please check the QVW and Excel file you will get the idea what i am looking for.

Thanks

Jitendra kumar Vishwakarma

Not applicable
Author

I think sir, i have not explain my requirement properly.

My requirement is when ever i select any date (if not select any date take max), goto previous week of that date. get all datewise dealer count and then get median of that.

aggr() will help to get NAME,DATE1 wise Dealercount in NAME dimension table.

aggr( sum(dealercount),NAME,DATE1)  but for previous week datewise i have used this :

aggr(sum({<DATE1=,WEEKSTARTDATE={"$(=date(max(WEEKSTARTDATE)-7,'dd-MMM-yyyy'))"}>} DEALERCOUNT),NAME,DATE1 )

and on top of this i put median() so i can get the value.

when i didnot select any date its working fine.... but if i select and particular date then the syntax is not able to get previous week dates according to selection.

avinashelite

Hi Jitendra,

I checked your file , here is my observation:

1.Your try to calculate the last week observation on the same day i.e current week Monday what was the count and last week Monday what was the count, in this case your expression is working fine but in your dashboard you does not have the data select 14 Nov you will get the result because 14 -7 = 7 and you have this date

2. If you want to use AGGR then those value has to be in dimension i.e

aggr(sum({<DATE1=,WEEKSTARTDATE={"$(=date(max(WEEKSTARTDATE)-7,'dd-MMM-yyyy'))"}>} DEALERCOUNT),NAME,DATE1 )

here you have  aggregating on Name and DATE1 but NAME is in the dimension but not the DATE1 hence it will not work

Not applicable
Author

Hi,

i have full last week Data.

i am not trying to calculate current Monday with previous Monday.

if i subtract 14-nov-2015 to 7 then i will get 07-nov-2015. that week is already there.

because i want name, date1 wise aggregation thats why i needs to add that too in it.

FULL DATA

NAME DATE1 WEEKSTARTDATE TURNOVER DEALERCOUNT
ABB07-Nov-201507-Nov-20151253
ABB08-Nov-201507-Nov-20154503
ABB09-Nov-201507-Nov-20153506
ABB10-Nov-201507-Nov-20153006
ABB11-Nov-201507-Nov-20151008
ABC07-Nov-201507-Nov-20152351
ABC08-Nov-201507-Nov-20152004
ABC09-Nov-201507-Nov-20152004
ABC10-Nov-201507-Nov-20151504
ABC11-Nov-201507-Nov-20152504
ABB14-Nov-201514-Nov-20151008
ABC14-Nov-201514-Nov-20152005

1). if i am not selecting any date1 then my max date1 is 14-nov-2015 and also my max weekstartdate is 14-nov-2015.

2). if i subtract 14-nov-2015 with 7 then i will get 07-nov-2015.

3). now what i will do is memberwise date1wise all the dealer count like this :

for ABB : (LAST WEEK)

NAME DATE1 WEEKSTARTDATE TURNOVER DEALERCOUNT
ABB07-Nov-201507-Nov-20151253
ABB08-Nov-201507-Nov-20154503
ABB09-Nov-201507-Nov-20153506
ABB10-Nov-201507-Nov-20153006
ABB11-Nov-201507-Nov-20151008

for ABC : (LAST WEEK)

NAME DATE1 WEEKSTARTDATE TURNOVER DEALERCOUNT
ABC07-Nov-201507-Nov-20152351
ABC08-Nov-201507-Nov-20152004
ABC09-Nov-201507-Nov-20152004
ABC10-Nov-201507-Nov-20151504
ABC11-Nov-201507-Nov-20152504

Now if you do Median on that displayed dealer count data of ABB you will get 6 and for ABC you get 4.

Displaying Current Week Turnover along with last Week Turnover and Median Dealer count.

NAME Current Date Turnover Last Week Turnover Last Week Median Dealer Count
300 2360 4
ABB10013256
ABC20010354

when i did not select any DATE1 its take max DATE1 and do all this which is working fine.

but if i select DATE1 as '14-Nov-2015' which is equivalent to max(DATE1)  but its did not work because DATE1 Dimension get into the effect.

i have try to by pass DATE1 Dimension in Aggr() Set Analysis but then also its not working.

Median(aggr(sum({<DATE1=,WEEKSTARTDATE={"$(=date(max(WEEKSTARTDATE)-7,'dd-MMM-yyyy'))"}>} DEALERCOUNT),NAME,DATE1 ))

Hope now you will understand what actually i want and what i am doing.

Thanks

Jitendra Kumar Vishwakarma

Not applicable
Author

Hi,

Try this that aggr function will not be associated with the current selection.

Median({<DATE1=}>}aggr(sum({<DATE1=,WEEKSTARTDATE={"$(=max(date(WEEKSTARTDATE-7,'dd-MMM-yyyy')))"}>} DEALERCOUNT),NAME,DATE1 ))

Regards

Gilles

MayilVahanan

Hi

May be try like this

Median({<DATE1=,WEEKSTARTDATE={"$(=date(max(WEEKSTARTDATE)-7,'dd-MMM-yyyy'))"}>}aggr(sum({<DATE1=,WEEKSTARTDATE={"$(=date(max(WEEKSTARTDATE)-7,'dd-MMM-yyyy'))"}>} DEALERCOUNT),NAME,DATE1 ))

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.