SSAS cube - calculations - ssas

I inherited a cube and I don't quite get what it's doing. It uses a dimension called "date tool" which really have members that have nothing to do with the facts table. It's members have calculation scripted. It plays with the time dimension, so you can get variances across time.
So one of the member calculate prior month variance (script below in Visual Studio)
For example - if I select March in the "date field", then [Prior Month Variance] from the "Date Tool" will give me the numbers for (March - February)
([DateTool].[Aggregation].[Prior Month Variance]) =
[DateTool].[Aggregation].[Previous Month] - [DateTool].[Aggregation].DefaultMember;
I want to amend this so that, when I select [month] = January, it display January only and not (January - December)
This is because (they decided to upload YTD data instead of MTD)

Related

How to pull next 2 quarter data with a data model that doesn't have fiscal time database and company defined fiscal year

I would like to pull all orders from the current, next and next to next quarter of the time stamp. I am able to pull up current quarter data but I am not able to pull next and next+1 quarter data.
I am currently using MS SQL Server 2013.
The time stamp also appears in a weird format. for eg.20191031_FY20_Q1_Wk1 whereas [Order Close Fiscal Year Quarter Display Code] appears as 2020-Q1. So to pull current quarter data I have used below condition:
(LEFT(Time_Stamp,2)+'20'+'-'+substring(Time_Stamp,15,2)) = [Order Close Fiscal Year Quarter Display Code]
What I logically want to do is this:
(LEFT(Time_Stamp,2)+'20'+'-'+substring(Time_Stamp,15,2)) = [Order Close Fiscal Year Quarter Display Code] + 1
(LEFT(Time_Stamp,2)+'20'+'-'+substring(Time_Stamp,15,2)) = [Order Close Fiscal Year Quarter Display Code] + 2
Obviously, I came across data type conversion error. I even tried using Dateadd() function:
[Opportunity Close Fiscal Year Quarter Display Code] = DATEADD(quarter,1, cast(left(time_stamp,8) as date) )
but still I keep coming across same error.
The MOST IMPORTANT THING I would like to HIGHLIGHT is my org's Fiscal Year is not same as generic Fiscal Year. In my org, Fiscal Year begins from Oct and ends in Sep. So I am not sure how even DateAdd() function will help. I believe having a Fiscal Time table customized as per org's Fiscal Year could be of great help for me but my manager thinks the BI team won't entertain such a request.
Any help in building this query would be really great!!
You would seem to have time_stamp values whose format is not as you describe.
You should find the column values that don't convert to a date:
select time_stamp
from t
where try_cast(left(time_stamp, 8) as date) is null and time_stamp is not null
With this information, you can debug your code or the data.

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.

MDX - Calculated MTD measure returning null value

I have a Cube with a Date dimension hierarchy (Year,Semester,Quarter,Month,Day).
There are 2 measures available in the datawarehouse.
[AUD DLY] : Daily numbers
[AUD YTD] : Daily incremental YTD numbers
Hierarchy is as follows
Date - Dimension
Financial - Hierarchy
Year - [Date].[Financial].[Year]
Semester - [Date].[Financial].[Semester]
Quarter - [Date].[Financial].[Quarter]
Month - [Date].[Financial].[Month]
Day - [Date].[Financial].[Day]
Measures [AUD DLY]
Measures [AUD YTD]
I need to add a MTD field in the measures such that when the business select a particular date on their slicer in excel for e.g., 3 March 2016, MTD should be calculated as either of the following ways :
1) [AUD MTD] should be calculated by subtracting [AUD YTD] on
last day of previous month from the current selected date.
So if we select 3 March 2016 then
[AUD MTD] = [AUD YTD] on 3 March 2016 - [AUD YTD] on 29 Feb 2016
OR
2) [AUD MTD] should be calculated by adding the [AUD DLY] from first day
of the current month until the selected date in that month.
So if we select 3 March 2016 then
[AUD MTD] = SUM ([AUD DLY] from 1 March 2016 to 3 March 2016)
I created a New Calculated Member from Calculations tab in the Cube designer in the BIDS 2010. The MDX query is below. However when I try to browse the cube the [AUD MTD] values are only returning nulls.
Can someone please help what am I doing wrong ?
CREATE MEMBER CURRENTCUBE.[Measures].[AUD MTD]
AS Aggregate
(
PeriodsToDate
(
[Date].[Financial].[Month]
,[Date].[Financial].CurrentMember
)
,[Measures].[AUD DLY]
),
FORMAT_STRING = "Currency",
NON_EMPTY_BEHAVIOR = { [AUD DLY] },
VISIBLE = 1 , DISPLAY_FOLDER = 'AUD Values' , ASSOCIATED_MEASURE_GROUP = 'Measures' ;
Also the business would be using the new calculated measure in excel using the Slicer, they want to select any date and be able to view the MTD value for that month.
Also can someone please help with MDX query for both methods (1) and (2) ?
Your help much appreciated.
I think the problem with your quoted code (method 2) is that [Date].[Financial].CurrentMember must be at a level at or below the [Date].[Financial].[Month] level. Otherwise PeriodsToDate returns an empty set.
So the problem is not in your calculated member definition, but somewhere in the query in which it's being used. In that query, [Date].[Financial].CurrentMember may be returning a member at a level above Months. Hard to see without seeing the query itself.
Method (1) is more fiddly. You can get the last day of the previous month with
Ancestor([Date].[Financial].CurrentMember,[Date].[Financial].[Month]).PrevMember.LastChild
but you'd have to build in some logic for days in the first month of the financial year, which would otherwise subtract the value for a previous fin year from this year's YTD value. So I'd recommend method (2).
As far as I know selecting a date (I mean a date, not a month) in the Excel slicer will make that date the .CurrentMember. I'm a bit hesitant because Excel does generate some deeply bizarre MDX sometimes.
EDIT: Another possible problem is a hierarchy mismatch. You can select a perfectly good Day in a date hierarchy, but if it isn't in exactly the hierarchy you specify in your calculated member definition, you can get weird results. IMHO more recent versions of SSAS encourage a proliferation of attribute hierarchies and multiple "real" hierarchies, making this a real problem.
As a test can you please add this very simple measure to make sure that currentmember is behaving as expected:
CREATE MEMBER CURRENTCUBE.[Measures].[AUD MTD]
AS [Date].[Financial].CurrentMember.member_caption
If when you use the above all it returns is the All member then you know something is wrong.
You need to double-check your relationships and datatypes used within your date hierarchies as this is often the reason for time calculation problems.
This is an alternative to your measure but I suspect if the original script is not working then neither will this...
CREATE MEMBER CURRENTCUBE.[Measures].[AUD MTD]
AS SUM
(
MTD([Date].[Financial].CurrentMember)
, [Measures].[AUD DLY]
)

Default prompt for date using month names from month numbers in OBIEE 11G analysis

Our database has a field for months as periods 1,2,3, . . . and a field for years. I would like the prompt to have month names instead of digits and I would like to have a prompt for my analysis that defaults the prior month from the time the report was run. I have year and month working in digit format(works for every month except if run in January) but I can't seem to get a solution that works with month names defaulting to the prior month.
The months need to be Year to Date, so <= the prior month.
I am in accounting so it is to get the ledger for the last day of the prior month. Each period month has just the activity for that month, so Prior year is 0, Current year activity is <>0 and the balance as of the month is 0 through the prior month.
I want users to be able to change the selections if they need but have defaults selected that they will use 99% of the time.
Right now, with the period numbers I was using
SELECT "Date"."Fiscal Period Nbr"
FROM "General Ledger"
WHERE "Date"."Fiscal Period Nbr" = (VALUEOF(Current_Month) - 1)
And for the years
SELECT "Date"."Fiscal Yr Nbr" FROM "General Ledger"
WHERE "Date"."Fiscal Yr Nbr" = (VALUEOF(Current_Year))
I created a group for each month selecting the periods, so January is 0,1 and February is 0,1,2 and so on. In the prompt I select those 12 groups and was trying to do some sort of SQL for the Default selection.

Algorithm to convert fiscal periods to calendar periods

What I am trying to do
I am somewhat desperately trying to build an algorithm which converts financial figures from different companies from fiscal periods to calendar periods.
The problem
Fiscal periods often do not correspond to calendar periods, e.g. a company might report fiscal year 2011 revenues of 100 USD but its fiscal year does not end at the end of December 2011 but instead on September 2011. For instance, Apple's fiscal year ends end of September. Dell's fiscal year ends end of January and Intel's fiscal year ends end of December. For Apple and Dell, all fiscal quarter and fiscal half year ends are shifted as well.
In order to compare revenues or other financial metrics among these companies, I need to be able to convert each fiscal period into equivalent calendar periods. For instance, someone might ask, how much revenue each company generated in calendar year 2011.
In the case of Apple Corp., we would need to remove the revenues which have been generated in calendar period 2010, which would equal Apple's fourth quarter of FY2010 and add the first quarter of fiscal year 2012 (which ended December 2011).
What I have (data model)
My data model has the following attributes for each entity calendarPeriod and fiscalPeriod:
endYear (year in which the period ends)
endMonth (month number
1..12 at which last day the period ends)
length (number of months 1..12 of the period)
What I need (desperately)
What would be the most efficient and short algorithm I could accomplish this?
It would be great if the algorithm could handle "special situations" like Dell where it would need to take 1/3 of its fiscal first quarter, which ends awfully on January, of the following year and adding it to the last quarter of the preceding year. In addition the algorithm should be flexible enough to handle all period lengths and endMonths and try to combine periods if necessary (for instance for the first half of calendar year 2012, it should try to find a six month period which ends June 2012 or consecutively add two periods (one ending March 2012 and one ending June 2012 or taking a fiscal year which ends June 2012 and subtracting the quarters or half year which fall in calendar year 2011).
Thank you so much.
This is more of a financial question then technical question.
If you have end of year results only, there is no practical way you could compare unless they are for same financial period.
Further, if you somehow manage to get the monthly results and do some juggling to prepare comparable results, they will not be comparable as there are many accounting adjustments and provisions generally done in the end of year financial result and not in monthly results which you will miss here.
I would suggest that you should try to compare those results which yields more meaningful results.