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: 
Not applicable

how to calculate share using variables in qlik sense

Want to calculate Share of products but facing this problem

I Have Been Using This Expression But It Is giving me error because it cant sum up the sales

Sum($(CURR_YTD_SALES))/Sum(Total($(CURR_YTD_SALES)))

So is There a way to sum up sales by using variables to calculate Shares

Thanks In Advance

15 Replies
Not applicable
Author

Gross Sales

if(num(GetSelectedCount(Year_new))=0

  or GetFieldSelections(Year_new)='2016' ,

    sum({<[DATE_FORMAT.autoCalendar.Month]=,[DATE_FORMAT.autoCalendar.Date]=

   {"$(= '>=' & '01-04-'& (Date(monthstart(Today()), 'YYYY')) & '<=' & '30-06-'& (Date(monthstart(Today()), 'YYYY')))"}>}GROSS_SALES_VALUE),

     sum({<[DATE_FORMAT.autoCalendar.Month]=,[DATE_FORMAT.autoCalendar.Date]=

    {"$(= '>=' & '01-04-'&Date(AddYears(date('01-04-'& GetFieldSelections(Year_new)),+0), 'YYYY') & '<=' & '30-06-'&Date(AddYears(date('30-06-'& GetFieldSelections(Year_new)),+0), 'YYYY'))"}>}GROSS_SALES_VALUE)

)

Similarly for Gross Return

shraddha_g
Partner - Master III
Partner - Master III

Just try to debug each variable.

according to your expression

It should be

(sum(Gross sales) - sum(Gross return))/(sum(Total Gross sales) - sum(Total Gross return))

it will give you share %

Not applicable
Author

its working this way but i want it dynamic thats why i used variables

but whenever i try to do the sum of a certain variable it fails

eg: in case of above variable

sum($CURR_YTD_SALES)/sum(total($CURR_YTD_SALES))

if i break down the above variable in 2 parts

1.sum($CURR_YTD_SALES)

2.sum(total($CURR_YTD_SALES))

so in both parts i cant sum up the variable

shraddha_g
Partner - Master III
Partner - Master III

create different variable CURR_YTD_TOTAL_SALES as

if(num(GetSelectedCount(Year_new))=0

  or GetFieldSelections(Year_new)='2016' ,

    sum(Total {<[DATE_FORMAT.autoCalendar.Month]=,[DATE_FORMAT.autoCalendar.Date]=

   {"$(= '>=' & '01-04-'& (Date(monthstart(Today()), 'YYYY')) & '<=' & '30-06-'& (Date(monthstart(Today()), 'YYYY')))"}>}GROSS_SALES_VALUE),

     sum(Total {<[DATE_FORMAT.autoCalendar.Month]=,[DATE_FORMAT.autoCalendar.Date]=

    {"$(= '>=' & '01-04-'&Date(AddYears(date('01-04-'& GetFieldSelections(Year_new)),+0), 'YYYY') & '<=' & '30-06-'&Date(AddYears(date('30-06-'& GetFieldSelections(Year_new)),+0), 'YYYY'))"}>}GROSS_SALES_VALUE)

)

and then use expression as

$(CURR_YTD_SALES)/$(CURR_YTD_TOTAL_SALES)

Not applicable
Author

Its Working But Its Giving 0.00%

Could You Tell me Why?

shraddha_g
Partner - Master III
Partner - Master III

Try $(CURR_YTD_SALES) and $(CURR_YTD_TOTAL_SALES) individually and see what values it gives?