Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
Month | Predict | Investment | Sales Forecast | Sales Prediction |
Jan | 3 | 200 | 10000 | 12000 |
Feb | 3 | 300 | 20000 | 22000 |
Mar | 3 | 600 | 67000 | 67500 |
Jan | 2 | 250 | 90000 | 99000 |
Feb | 2 | 300 | 80000 | 81000 |
Mar | 2 | 50 | 85000 | 0 |
Jan | 1 | 300 | 67000 | 67600 |
Feb | 1 | 600 | 90000 | 0 |
Mar | 1 | 250 | 80000 | 0 |
Is it calculated only for 3 Months of data? If you can provide some sample data it will be helpful
Yes, 3 months is the maximum. There data in my original post should be sufficient to solve this.
//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;