Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
qlikie
Contributor II
Contributor II

ROI calculation based on selections

Hi, I'm trying to calculate return on investment (ROI) based on the below data. If 'Predict' is '3', I calculate it as follows: 

ROI=(Sales Prediction for 3 months -Sales Forecast for 3 months)/Investment for 3 months

However, when 'Predict' is '2', I'm not interested in March data because I have no Prediction for it, and Forecast data should be excluded from the calculation. 

My ROI would be calculated as follows:

ROI=(Sales Prediction for 2 months -Sales Forecast for 2 months)/Investment for 2 months

Similarly, when 'Predict' is '1', I'm only interested in ROI in January.

I'd appreciate your help! 

MonthPredictInvestment Sales ForecastSales Prediction
Jan32001000012000
Feb33002000022000
Mar36006700067500
Jan22509000099000
Feb23008000081000
Mar250850000
Jan13006700067600
Feb1600900000
Mar1250800000
Labels (4)
3 Replies
Kushal_Chawda

Is it calculated only for 3 Months of data? If you can provide some sample data it will be helpful

qlikie
Contributor II
Contributor II
Author

Yes, 3 months is the maximum. There data in my original post should be sufficient to solve this. 

Kushal_Chawda

//script solution
Data:
LOAD date(date#(Month,'MMM'),'MMM') as Month,
     Predict, 
     if(Predict=3,1,if(Predict=2,if(Month<>'Mar',1,0),if(Predict=1,if(Month='Jan',1,0)))) as Flag,
     Investment, 
     [Sales Forecast], 
     [Sales Prediction]
FROM
[https://community.qlik.com/t5/New-to-Qlik-Sense/ROI-calculation-based-on-selections/m-p/1667500#M156092]
(html, utf8, UserAgent is 'Mozilla/5.0', embedded labels, table is @1);

Final:
LOAD Predict,
     (sum([Sales Prediction])-sum([Sales Forecast]))/sum(Investment) as ROI
Resident Data
where Flag=1
Group by Predict;