profit forecast using sql? - sql

I have a set of profit for the year data in a csv file and I would like to create a simple forecast for the upcoming year. I've seen some using Simple moving averages? but from what I see is that its just calculating an average so how does that forecast anything?

Related

Calculate Monthly Average With Multiple Records in a Month

I have a dataset with the structure below.
I want to calculate a monthly average of the views.
I attempted to calculate the yearly frequency with the following code and I believe it is correct
SELECT
EXTRACT (YEAR FROM TO_DATE("date",'Month YYYY') ) AS "year",
AVG("views")
FROM talks
GROUP BY EXTRACT (YEAR FROM TO_DATE("date",'Month YYYY') )
ORDER BY "year" DESC
When it comes to the monthly analysis I have the problem that there several records for the same month in a year and there several years with the same months (in reality the dataset has information for many years - this a reduced version).
How can I go to implement this?
If you want the average per month then just group by your current date field.
If you want the average per month regardless of year then you would have to extract the month part of the current date field and group by that.
But your date field now appears to be having string data type; it would be better to use proper date data type. Then your analysis would be much easier, more flexible, better performing.

Calculating the no. of days for the selected date period using MDX

I am trying to create a calculated column on a SSAS cube to work out the following:
Net Net X Rate = [Net Net Revenue] / [X]
where X = no of days
I need an output for X (using MDX), Something like the no. of days for the date period selected
For example upon the selection of
30 days for the chosen month of April 2021
X = 30
rate for 30 days
14 days for the chosen month of December 2020
X=14
rate for 14 days
I don't have access to SSAS at this point, but maybe somthing like
Net Net X Rate = [Net Net Revenue] / COUNT( EXISTING [Date].[Calendar].[Day].Members )
Answered here maybe: Count children members in MDX
Maybe this could help: DateDiffDays or .
I had something like this in mind: DateDiffDays([Measures].[From_Date], Now()). It will count the days difference between some day in the past and now. DateDiffWorkdays will get you a number of working days between two dates.
Alternatively, you could pre-calculate this value in a view and then pull the number into a cube.
Assuming your Date dimension is on day granularity, a very efficient way from query performance point of view to get what you want would be to add a column to your date dimension table. This could either be done in a view in the relational data model, or in the DVS as a calculated column. Name it e. g. number of days or just X, and make it be the value 1 on each row, i. e. the column expression is just 1. Then you create a new measure group based on this table, with the only measure being X, which would just sum this column. Then, whatever your query context would be, the X measure would just be the number of days. If you want, you can then make the measure invisible.

get weather forecast for day and night only

I am hoping to use openweathermap for forecast but on a daily basis (one forecast per day), instead of ever 3-hour per day forecast.
I don't thikn OWM have such an end point but is there away it can be calculated once data is retrieved?

Pass parameter to MDX/Tabular Object Model Cube using tableau parameter/filter

I have below things:
Tableau report (with Year and Month)
The tableau report is pointing to Tabular Object Model Cube
Tabular Object Model contains date dimension, region dimension and fact sales
Trying to achieve below:
When the user selects a year and a month from the report, the report should give me sales for previous 3 quarters with reference to the month selected
If your solution proposes to use a MDX query, then it would be great if you can point to some link, to illustrate how this can be done.
I have tried below:
Dragged Year and Quarter in rows(in tableau) and dragged the calculated field in column. This gives me sales across all quarters for all years but I want to limit this information to previous 3 quarters based on the Year and month selected by the user.

YoY comparison in Qlikview using Dimension values

Can we do a year on year comparison using the dimension input in an expression? This is what I am trying to do. My dimension is Year and in the expression I want to show the total sales (e.g) for the selected dimension as that of the previous year?
It should look something like this:
Year Current sale Last year
2013 1000 1500
2012 1500 1200
2011 1200 1100
Is this doable or is it something I have to accommodate for in the data modelling layer?
If you're using straight table, you need to accommodate this on your data model layer, but if you're using this with another dimension, and only showing single year, you can use set analysis:
Current Year Expression: SUM({$<Year={$(=MAX(Year))}>}Sales)
Last Year Expression: SUM({$<Year={$(=MAX(Year)-1)}>}Sales)