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: 
imrasyed
Partner - Creator II
Partner - Creator II

Set Expression YTD not working

Hi Experts,

I have an expression below for which iam not able to get the YTD correctly.

Can you please let me know where am I going wrong.

Sum(Aggr(Sum({$<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[80,81,88,93]}>+<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[>=100 and <=299]}>}[Extended Invoice Price]),[Product Number])

/

Aggr(Sum({$<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[80,81,88,93]}>+<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[>=100 and <=299]}>}[Unit Sales]),[Product Number]))

To make it simpler it is

Sum(aggr(Sum({<Date=YTD>}Extended Invoice price),product)

/

Aggr(Sum({<Date=YTD>}Unit Sales),Product))

1 Solution

Accepted Solutions
sunny_talwar

May be try this:

Sum({<Date=YTD>} Aggr(Sum({<Date=YTD>}Extended Invoice price)/Sum({<Date=YTD>}Unit Sales), product))

two changes:

1) Used the inner set analysis to the outer set analysis

2) Instead of using two Aggr(), I used just one now since they are both aggregating over just a single dimension product

View solution in original post

8 Replies
MK9885
Master II
Master II

Maybe

Sum(aggr(Sum({<Month = {"<=$(=num(Month))"} >}Extended Invoice price),product)

/

Aggr(Sum({<Month = {"<=$(=num(Month))"} >}Unit Sales),Product))

imrasyed
Partner - Creator II
Partner - Creator II
Author

Thanks Shahbaz but if you see my above Expression thats what I have written which is not giving me the correct result

MK9885
Master II
Master II

Sum(aggr(Sum({<Month = {"<=$(=num(Month))"} >}Extended Invoice price),product)

/

Aggr(Sum({<Month = {"<=$(=num(Month))"} >}Unit Sales),Product))

Month = {"<=$(=num(Month))"} here is your YTD expression.

Not sure if you mean aggr is not working or the YTD is not?

imrasyed
Partner - Creator II
Partner - Creator II
Author

Yup shahbaz

My YTD Expression is working with other set analysis expression having no aggregation on them.

So its not the issue with my YTD expression.Please check the Expression below

Sum(Aggr(Sum({$<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[80,81,88,93]}>+<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[>=100 and <=299]}>}[Extended Invoice Price]),[Product Number])

/

Aggr(Sum({$<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[80,81,88,93]}>+<[DePuy Fiscal Year/Month ]={">=$(=Date(Yearstart(Date(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),'YYYYMM')),'YYYYMM'))<=$(=Date(Addmonths(addyears(date(date#(max([DePuy Fiscal Year/Month ]),'YYYYMM'),'YYYYMM'),0),-1),'YYYYMM'))"},

[Customer Salesman Code]={'C'},DIVISION_ID ={1,3},[Domestic International Code]={'D'}, [JIT Flag]= {'N'},

[Cust.CustomerNo]-={'7*'},[Territory Number (Time of Sale)]={[>=100 and <=299]}>}[Unit Sales]),[Product Number]))

MK9885
Master II
Master II

Its quite a big expression...

stalwar1‌ is an expert is Aggr & set..

Hopefully he can help you with this.

Thanks.

sunny_talwar

May be try this:

Sum({<Date=YTD>} Aggr(Sum({<Date=YTD>}Extended Invoice price)/Sum({<Date=YTD>}Unit Sales), product))

two changes:

1) Used the inner set analysis to the outer set analysis

2) Instead of using two Aggr(), I used just one now since they are both aggregating over just a single dimension product

imrasyed
Partner - Creator II
Partner - Creator II
Author

Thanks a Lot Sunny.

Its working like expected.

Thanks again.

imrasyed
Partner - Creator II
Partner - Creator II
Author

Thanks Shahbaz for helping me.