Analysis Services - MDX - Comparing diffrent years data month by month - service

I am a total beginner with analysis services / performance point and I need some help to create a diagram.
I am using the Contoso sample database.
I found a tutorial which helped me to create the following diagram:
Months on X axis,
Sales amount on Y axis
and I displayed the data for the years 2008 and 2009
So with this diagram I get on X axis the months from January 2008 to December 2009. (I use data from [Date].[Calendar Month])
The problem is that I need to compare data of different years month by month.
So on the X axis I need to display the month from january to december regardless of year information.
I tried to use MDX query and the parrallelperiod function but I could not display what I need. I thought I need to group the data by the name of the month so I tried unsuccessfully to use 'group by' like in sql.
Maybe I need more data in the cube ? like the list of the months (without the year relation)
I'm not sure about the direction to take, any help would be greatly appreciated. I can provide more details if you need.
(It seems that adventurework has pretty similar dimensions so if someone did the same thing with this cube it would be great too.)
[EDIT]
Here is the query automatically generated:
SELECT
HIERARCHIZE( { [Date].[Calendar Month].&[200901], [Date].[Calendar Month].&[200902], [Date].[Calendar Month].&[200903], [Date].[Calendar Month].&[200904], [Date].[Calendar Month].&[200905], [Date].[Calendar Month].&[200906], [Date].[Calendar Month].&[200907], [Date].[Calendar Month].&[200908], [Date].[Calendar Month].&[200909], [Date].[Calendar Month].&[200910], [Date].[Calendar Month].&[200911], [Date].[Calendar Month].&[200912], [Date].[Calendar Month].&[200812], [Date].[Calendar Month].&[200811], [Date].[Calendar Month].&[200810], [Date].[Calendar Month].&[200809], [Date].[Calendar Month].&[200808], [Date].[Calendar Month].&[200807], [Date].[Calendar Month].&[200806], [Date].[Calendar Month].&[200805], [Date].[Calendar Month].&[200804], [Date].[Calendar Month].&[200803], [Date].[Calendar Month].&[200802], [Date].[Calendar Month].&[200801] } )
ON COLUMNS,
HIERARCHIZE( { [Date].[Calendar Year].&[2008], [Date].[Calendar Year].&[2009] } )
ON ROWS
FROM [Sales]
WHERE ( [Measures].[Sales Amount] )
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR
[/EDIT]
Thank you.

Change attribite relationships between Time dimensions attributes as following:
Date->Month->Year and then you can chose whatever Year in the filter, the month in the X axis will be for a corosponding Year. If you have May in X Axis and not choosen any year (by default is All member) then you will have accumulated all May's, but if you choose Year 2010, down you will have May 2010 and if you choose in teh filter Year 2011 in X axis you will May 2011.

If you do not want to change the relationship between the time dimension attributes you can like this one:
WITH SET [months_2008_2009] AS { [Date].[Calendar Year].&[2008].Children, [Date].[Calendar Year].&[2009].Children }
MEMBER [Date].[Calendar Month].[January] AS Aggregate(Filter([months_2008_2009] , [Date].CurrenMember.MemberValue = 'the member value for January'))
MEMBER [Date].[Calendar Month].[February] AS Aggregate(Filter([months_2008_2009] , [Date].CurrenMember.MemberValue = 'the member value for February'))
SELECT {[Date].[Calendar Month].[January], [Date].[Calendar Month].[February]} ON COLUMNS
FROM [Sales]
WHERE ( [Measures].[Sales Amount] )
In [months_2008_2009] there should be all the months in 2008 and 2009.
[Date].[Calendar Month].[January] is a calculated member that will be the aggrgation of [Date].[Calendar Month].&[200801] and [Date].[Calendar Month].&[200901]. You have to add other members for the other months.
I assumed than [Calendar Year] and [Calendar Month] are two levels that belong to the same hierarchy.

Related

How to dynamically calculate the YTD for current year without using a table calculation in Tableau?

How do I dynamically calculate the Year To Date (YTD) for the current year without using a table calculation in Tableau?
I have used the below formulas to calculate YoY for the current year:
if datediff('year',[Date],TODAY())=0 then [Sales] END
For the previous year:
if datediff('year',[Date],TODAY())=1 then [Sales] END
YoY:
sum(current year)/sum(previous year)-1
create a calculated field:
[date] >= MAKEDATE(Year(today()),1,1) and
[date]<= today()
Drag this to filter and select True
It depends on what you're trying to achieve. If you want to filter dates to show only values in the current year without a table calculation, then you could create a calculated field like below and filter on the result:
if Year([Date]) = YEAR(TODAY()) then "YTD" else "Not" END

How to Create Calculated field for last 7 days sales

I am trying to create one calculated field for last 7 days and want to display same info for like total order value,Total orders, Total Ordering retailers
My Formula for Calculated Field
IF ATTR([CreatedDate])>=TOTAL(MAX([CreatedDate]))-6 THEN
SUM([OrderAmount])
END
Create a new calculated field called [Day Index] that indexes your date field by day:
DATEDIFF('day', [Date], today())
Then a new field per measure to get the value for the last 7 days:
IF [Day Index] <= 6 THEN [Total Orders] END
The 6 assures you data source includes the current day also, if it doesn't then you may want to adjust this to 7.
create calculation :
[order Date] >= (TODAY()-7)
drag this calculation into filter and select TRUE

Create a measure to return the maximum date about the order in a fact table. (SSAS Multidimensional)

I want to create a measure which return the maximum date about Orders but before the actual day
I will write an example :
My tables here
(In my table Calendar i have the year 2016,2017,2019, and in my Order table, i have an order for 2016 and 2019,
I want the last date order but before the actual day (18/05/2017), so i want the Date 01/01/2016).
I have 2 table, a dimension Calendar and a fact table Order.
I was thinking about the function filter, so i search how to use filter in
google, and all the solutions i found use 'With' and 'Select'.
(I can't use 'With' and 'Select' when i create a measure in SSAS multidimensional).
Hope i will see your advice.
Just like this similar case in adv cube?
[max order date] return the maximum date about [Internet Sales Amount]
with member [max order date] AS
tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales Amount])).item(0).item(0).PROPERTIES( "name" )
select {[max order date] } on 0 from [Adventure Works]
if yes, then you can create a measure in your cube like this:
Create Member CurrentCube.[Measures].[max order date]
As tail(NONEMPTY([Date].[Date].[Date],[Measures].[Internet Sales
Amount])).item(0).item(0).PROPERTIES( "name" );
if only till current day, then(following is refer to adv cube, you need do some code changes per your cube):
Create Member CurrentCube.[max order date] AS
Tail
(
NonEmpty
(
{
Head([Date].[Date].[Date]).Item(0).Item(0)--the first day in your Date dim
:
StrToMember("[Date].[Date].&[" + Format(Now(),"yyyyMMdd") + "]")-- as of current day
}
,[Measures].[Internet Sales Amount]
)
).Item(0).Item(0).Properties("name")
IDE to Write, Analyze, Tuning, Debug MDX efficiently (www.mdx-helper.com)

LOD (Level Of Detail) where Year =

Trying to write a Calculation in Tableau that allows me to Fix Level of Detail on Category where year equal a designated date.
Imagine looks something like
{FIXED [REPORT CATEGORY] : AVG(DOLLARS PAID)} WHERE YEAR = 2015
You have a couple of options.
1) You add the YEAR dimension to the LOD calculation and then add the Year to the filter card and set to '2015'. Your calculation would look like this:
Since you have no YEAR, you need to create a calculated field for it then reference it.
"YEAR" : YEAR(APCD PAID ACCNTS DATE)
{ FIXED [REPORT CATEGORY], [YEAR]: AVG(DOLLARS PAID) }
2) You can restrict the aggregation to only a specific year in the calculation, like so:
{ FIXED [REPORT CATEGORY]: AVG(IF YEAR([APCD PAID ACCNTS DATE]) = 2015 THEN DOLLARS PAID END) }
-- EDIT --
Updated above because you stated you are using a DATE not a number of the year.

SSAS 2012 How to use ParallelPeriod without Date Hierarchy?

I found an example of how to use the Parallel Period function in my SSAS OLAP Cube here: https://www.mssqltips.com/sqlservertip/2915/sql-server-analysis-services-period-over-period-variance-analysis/
However it assumes that you have a Date Hierarchy, which I don't. I tried using it without success. My Date Dimension only has a date attribute and a Year Month attribute (ex: 2015/01 for January 2015). It has no hierarchy nor anything else.
(Interested why? Because it just works, and a hierarchy confused my users)
I need to compare values month over month and year over year.
This is what I could infer with the example, but it is not working:
IIF([Fact Date].[Date].CurrentMember.level.ordinal = 0,
[Measures].[Billed Amount],
(ParallelPeriod([Fact Date].[Year Month].[Year Month],
1,
[Fact Date].[Date].CurrentMember),
[Measures].[Billed Amount]
)
)
What would be the correct syntax to achieve this?
At the end I fixed it adding a Year attribute (ex: 2015), Month attribute (ex: 201501), and made a simple hierarchy (Year, Month, Date). It worked with the following code:
IIF([Fact Date].[Date Hierarchy].CurrentMember.level.ordinal = 0,
[Measures].[Billed Amount],
(ParallelPeriod([Fact Date].[Date Hierarchy].[Month],
1,
[Fact Date].[Date Hierarchy].CurrentMember),
[Measures].[Billed Amount]
)
)