Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Calculate the percentage of each Month Sales against Forecast

Hi,

I am currently trying to calculate the percentage of spend for each month of the year against each other. The following table is my data set with a CurrentDateKey in a different table that defines the current month of the year that uses the same format as the DateKey.

      

DateKeyStoreMonthSalesSales ForecastFinancialYear
072017Store1July3253552017
082017Store1August10202017
092017Store1September1251352017

The following code for my demension calculates the sales and forecast of all the months that have past cumulatively to define the percentage of sales against the forecast for the total year to date. Then defines the percentage of sales per store but just counting the stores for the related dual value.

What I want to be able to do is calculate the percentage of sales against forecast for each month against each other.

What the current code calculates =  (325+10+125) / (355+20+135) =  90.1% of expenditure against forecast

How I want the code to calculate = (325/355) + (10/20) + (125/135) = 78% of expenditure against forecast

Aggr(

if(Sum({$<FinancialYear={'2017'} >}Sales)/Sum(if(DateKey >= '072017' and DateKey < (CurrentDateKey), Sales Forecast)) > 1.5, Dual('Greater than 150%',5),

if(Sum({$<FinancialYear={'2017'} >}Sales)/Sum(if(DateKey >= '072017' and DateKey < (CurrentDateKey), Sales Forecast)) > 1.25, Dual('126% - 150%',4),

if(Sum({$<FinancialYear={'2017'} >}Sales)/Sum(if(DateKey >= '072017' and DateKey < (CurrentDateKey), Sales Forecast))  >= .75, Dual('75% - 125%',3),

if(Sum({$<FinancialYear={'2017'} >}Sales)/Sum(if(DateKey >= '072017' and DateKey < (CurrentDateKey), Sales Forecast))  >= .50, Dual('50% - 74%',2),

if(Sum({$<FinancialYear={'2017'} >}Sales)/Sum(if(DateKey >= '072017' and DateKey < (CurrentDateKey), Sales Forecast))  < .50 , Dual('Below 50%',1),

))))),Store)

Thanks,

William

1 Solution

Accepted Solutions
sunny_talwar

Or this

Sum(Aggr(Sum(Sales)/Sum([Sales Forecast]), DateKey, Store))

View solution in original post

3 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Instead of Sum(X)/Sum(Y)

you should try

Sum(X/Y)

which will first divide and then add those values.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
sunny_talwar

Or this

Sum(Aggr(Sum(Sales)/Sum([Sales Forecast]), DateKey, Store))

Anonymous
Not applicable
Author

Thanks, this worked for me.

The other answer by Kaushik does work in some instances but if a store has two forecast rows for a single month it doesn't calculate properly.