MDX_How to ignore filtered date in rolling average - ssas

I have a problem with defining Rolling Average for last 7 days. When the user opens my dashboard ,the default filter for "Date" is set for last 30 days and, this calculated Measure (RollingAverage7Days) is not correct for the first 6 days of filtered date period(because it refers to the days that are filtered).
I need to change this mdx formula to ignore the "Date" filter by user:
Sum
(
{
[DimDate].[Persian Date].CurrentMember.Lag(6)
:
[DimDate].[Persian Date].CurrentMember
}
,[Measures].[SumPrice]
) /7
*The green line in the following linechart shows RollingAverage7Days.As you can see for the first 6 days, this calculated measure doesn't have a correct value.
Can anybody help me out of that?

Related

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.

Sum values on date table where one column equals a selected value from another

I have a DimDate table that has a Billable Day Portion field that can be between 0 and 1. For each day that's in the current Bonus Period I want to multiple that Day Portion by 10, and then return the total sum.
To find out what Bonus Period we're in, I return ContinuousBonusPeriod where the date equals today:
Current Continuous Bonus Period:= CALCULATE(MAX(DimDate[ContinuousBonusPeriod]), FILTER(DimDate, DimDate[DateKey] = TODAY()))
I can see in the measure display this is correctly coming back as Bonus Period 1. However, when I then use ContinuousBonusPeriod in the measure to determine the number of days in the current period, it only returns 10, 1 day multiplied by the static 10.
Billable Hours This Period:= CALCULATE(SUMX(DimDate, DimDate[Billable Day Portion] * 10), FILTER(DimDate, DimDate[ContinuousBonusPeriod] = [Current Continuous Bonus Period]))
It appears to be only counting today's DimDate record instead of all the records whereContinuousBonusPeriod = 'Bonus Period 1' as I'd expect.
I needed to make sure no existing filter was applied to the DimDate table when calculating the Current Continuous Bonus Period:
Current Continuous Bonus Period:= CALCULATE(MAX(DimDate[ContinuousBonusPeriod]), FILTER(ALL(DimDate), DimDate[DateKey] = TODAY()))
(Notice the ALL() statement)

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.

Tabular Query to Compare Measures Across Dates

I've got a number of rows and I want to calculate the difference per date.
So say I have the following:
[Date] [Transaction Number] [Value]
1 Jan 16 1 1000
2 Jan 16 1 980
I then want a fact that for every row will compare the value with the measure from the previous date.
So If I have a measure on SUM(Value) for the current date, I basically want SUM(CurrentDate) - SUM(PreviousDate) to see the movement.
A couple of things to note:
There will actually be a couple of comparisons: previous date, previous month end, previous year end.
I want this as a calculated measure not column so that I do not need to filter on the transaction number in the previous period.
What I've tried but it just comes up empty:
Previous Value :=CALCULATE(SUM(Table[Value])) - CALCULATE(SUM(Table[Value]), FILTER(Table, Table[Date] = PreviousDay(Table[Date])))
Unfortunately I cannot tell why your measure didn't work, but following should:
Previous Value := CALCULATE(SUM(Table[Value]) - CALCULATE(SUM(Table[Value]), PREVIOUSDAY(Table[date])))

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.