Understanding the calculation in MDX - mdx

I would like to understand how the cube calculates values at different levels.
I have defined Calc as Calc = sum(Y over 12 months including current month)/sum(X over 12 months excluding current month)only for the month in the cube.
The values in month match the expected values when calculated manually. But I don't understand how the cube interprets this formula at the quarter and year level. I am not able to get the same values as in calc column when calculating manually.
Can someone explain me?Thanks.

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.

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.

How to filter DATESBETWEEN based on column value (to calculate number of business days in a month)

Working on an SSAS Tabular project in Visual Studio 2010;
I'm trying to create a measure that calculates the total number of business days in a month:
I have Month Start Date and Month End Date measures, and Date and Is Business Day columns.
I can create a Total Business Days measure with COUNTROWS(FILTER(Dates,Dates[Is Business Day]=TRUE())). That gives me the number of business days in the context, but I want the number of business days for the current month.
I've tried various combinations of FILTER, COUNT, COUNTX, COUNTROWS, DATESBETWEEN, and CALCULATE without success.
What I want is a count of days between two dates, where the column [Is Business Day] is true, but I can't seem to get the right combination of filtering.
I would guess I filter the Dates table the way I do for the Total Business Days measure, but FILTER returns a table and COUNTROWS expects a single column - is there a way to get single column from a FILTER result?
Here's one thought...
First, create a calculated column called MonthKey (if you don't have it already):
=YEAR([Date]) * 100 + MONTH([Date])
Then create another calculated column called IsCurrentMonth
=IF(YEAR(TODAY()) * 100 + MONTH(TODAY()) = [MonthKey], 1, 0)
Then you can create your calculated measure as
COUNTROWS(FILTER(Dates,Dates[IsCurrentMonth] = 1))
Would that do what you need?

SSRS - How to get subtotals for a set of 12 records in a column

I am novice with SSRS.
I have a report which should display 60 months (5 years displayed like Jan 1999, feb 1999 & so on till the end of 60 months) and its corresponding sales amount. I want to get averages for the first 12 months (i.e for the 1st year) and so on. Is it possible? My dataset just gives me all the 60 months row-by-row.I am using matrix for my report.
Thanks,
User007.
I would add some nested row grouping to the matrix. The higher-level group would be by year, which would allow you to have a row in the matrix that totals/averages all of the data for the year. The inner group would be by month, giving you the individual month rows as your dataset returns them.
Here is some information about defining and using groups

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.