SQL QUERY: Sum of amounts equal to last day of reporting month & cutoff date is equal to and greater than reporting month - sql

I am trying to ask this question as best as i can so please forgive me inadvance if its not 100% clear.
I have a set of data which shows the date a transaction is processed.
For the same set of data I have the date of cut-off
what i am trying to achieve is finding the sum of transactions where:
Processed in a given month but the cut-off date is on the last day of the reporting month or future dated
e.g.
From the above on May-22 should have 100 and Jun-22 i should have 200 that has not met the original deadline.
Any help on this would be great. I have tried a few solutions but could not make them work

Related

How to extract Ageing report using SQL?

How to prepare an ageing report using SQL to identify how much payment has been due for
a. 90-120 days
b. 60-90 days
c. 30-60 days
d. 0-30 days
This should be calculated as on 6th April 2016.
Output should be like -
http://sqlfiddle.com/#!9/d83f4/1
Good question.
You would need to add a column or two in order for you to get this.
You'll need to have a calculated column letting you know the difference in days from today's date to the date of service/sale.
One more column is needed here, and that will "bucket" the record as per your pre-assigned buckets.
You can have a case statement do the work for each of these columns.
If you post some queries showing some work along these lines, we, at SO can help you along to correct your calculation.

How do I summarise month to date forecast for current month in Power Pivot?

I have a table in a data model that has forecast figures for the next 3 months. What I want to do is to show what the forecast number for the current month to date is.
When I use the DATESMTD function like this:
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]),DATESMTD(DateTime[DateKey]))
I get the last month of my data summarised as a total. I assume that is because the DATESMTD function takes the last date in the column and that is 3 months away.
How do I make sure I get this current month MTD total rather then the end of the calendar? The formula should be clever enough to realise I am in May and want the May MTD not the August MTD.
Any ideas?
The way to do this is to do this:
Forecast_Transaction_MTD:=CALCULATE(sum('ATO Online'[2017 Transaction Forecast]), DATESINPERIOD('ATO Online'[Current Year],TODAY(),-day(TODAY()),day))
the last -day(TODAY()) gets the day number for the current day and subtract it from today's date. So, today is the 25 May. the -day(TODAY())),day)) extracts the day (25) and subtracts it from the current date to get me to the 1 May.
The rest of the formula just adds the total for the dates.

SQL Query that rund monthly on a fixed day range

I have an SQL query I need to run once a month.
The data set the query produces always has to be from the 11th of the month before to the 10th of the current month.
I now manualy run the query in the fews days after the 11th day of the month manually adjusting the date range in my where statement:
for example...
Where Column A is greater than 10/10/2015 and less than 12/11/15
I was hoping there would be a statement I could add to my query to automatically find the 11th day of the last month and the 10th of the current month. This way I could schedule the query and automatically email the results.
You should be able to use the following within your query: -
CONVERT(date,FORMAT(GETDATE(),'yyyy-MM')+'-10')
(for the 10th of this month)
and
CONVERT(date,FORMAT(DATEADD(m,-1,GETDATE()),'yyyy-MM')+'-11')
(for the 11th of last month).
Try to look out the MONTH() function in your working DBMS. In MySQL and MSSQL it returns a number (1 been january) corresponding to the current month that your system is (you may check if it's date is updated).
With this function you can subtract 1 to get the last month, having to do some logic when the current one is January, hence 1. Since now you should get 12 (december) intead of 0 (an error).
Cheers, mate!

Average of Last 90 days data, but for each hour samples in a day using MDX query

I have a measure as 'power' rollup as SUM, Time dimension as Year->Month->Day->Hour, and Location Dimension.
We are storing at hour level of power data.
Now we require for a particular location and date, last 90 days average power for each hour. It should display 24 columns with average last 90 days power_total for each hour.
The following query gives only that date's power for each hour for a location1. But I need last 90days average power for each hour in a date and location. How to do this requirement?
SELECT
{Hierarchize({[Time.Monthly].[2013].[9].[20].Children})} ON COLUMNS,
NON EMPTY {CROSSJOIN({Hierarchize({[Location].[Location1]})},{[Measures].[power]})} ON ROWS
FROM [Power_Trend]
I am pretty new to MDX.
Please help me out.
-Prakash
You can use LAG function to create a date range: description with some simple examples
Secondly you should create current date member with strtomember, for example:
strtomember("[Time.Monthly].["+cstr(year(now())) + "].[" + cstr(month(now())) + "].[" + cstr(day(now())) +"]")
I have asked the same question in pentaho forum. It has bean answered.
http://forums.pentaho.com/showthread.php?150250-Average-of-Last-90-days-data-but-for-each-hour-samples-in-a-day&p=355155

MDX Beginning to Current Date Sum

This is regarding calculating the sum for a set of values starting from the date a measure has entries till the current date.
So far what I could find was the YTD function. This limits the aggregation capability till the current date beginning from the first day of the year. But what my requirement is to start the calculation from the first value, this could be in the last year or may be two years before.
Eg:
Date-----------Value
11/9/2010-----2000
2/10/2011-----500
8/5/2011------1000
With YTD the value is: 1500
What I need is: 3500
I really appreciate any help on this.
Something like:
SUM([Date].[Day].AllMembers, [Measures].[Value])
OR
SUM(OpeningPeriod([Date].[Day]):ClosingPeriod([Date].[Day]), [Measures].[Value]),
where [Date].[Day] - it's a level DAY of your dimension;
[Measures].[Value] - your measure.