MDX Beginning to Current Date Sum - sql

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.

Related

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

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

Power BI - Difference between amount per day and total in a table

I have a table with the sales from last 2 years, and I want to compare the sales from this year with the same natural day last year. For example, Sunday 1st of April 2018 will be compared with Sunday 2nd April 2017.
In order to do that I have created the measure
sales_last_year = CALCULATE(Sales[Revenue]); SAMEPERIODLASTYEAR(DATEADD('Calendar'[Date];+1;DAY)))
And I have created another measure where I have the value from the same day last year:
Prueba_sales_last_year = CALCULATE(Sales[Revenue]); SAMEPERIODLASTYEAR('Calendar'[Date]))
The result is the following:
Sales last year
As you can see the sales per day shows 5.316€ and 3.546€, which is correct, but the total is 111.796 €, which is not correct. However, the measure with the formula without the natural day the sum of the two rows is correct. How could I solve this?
Thank you very much in advance
I just changed the order to calculate the date and it was solved.
sales_last_year = CALCULATE(Sales[Revenue]);DATEADD( SAMEPERIODLASTYEAR('Calendar'[Date]);+1;DAY))

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.

create calculated member based on date for condition

I have a Date dimension that I would like to check current month and current year, and then display a different Measure depending on that evaluation.
example:
MM - 04
YY -2016
Calculated member determines current month then for months prior(1-3) it shows measure Qty Shipped. For current month and beyond(4-12) it shows measure Forecast. This logic is only working with current year.
Thanks.
IIF(([02 Dates].[MM].currentmember,[Measures].[Qty Shipped])<
(
STRTOMEMBER('[02 Dates].[MM].&['+format(now(),'yyyy')+']&['+format(now(),'MM')+']')
,[Measures].[Qty Shipped]),
[Measures].[Qty Shipped],
[Measures].[Current Forecast])
Seems to do the Current Month on correctly, but doesn't move qty shipped to months 1-3.
Thanks
Does this logic look correct.
Any help much appreciated.

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!