I need to create a calculation or KPI (I am not sure what exactly) which helps to compare to dates from different dimensions.
I have a cube and I need run a report when I pick up Course date and Absence date for a student if the dates are the same then a value should be missing.
This is a SQL query which is perfectly working but I need to implement it in a cube:
case when AbsenceDate=CourseDate then'missing'
else 'not the same date' End as 'date info'
If I was writing a script and needed the measure, it would probably look vaguely like this:
WITH
MEMBER [Measures].[date info] AS
IIF(
[AbsenceDate].CURRENTMEMBER.MEMBER_CAPTION
= [CourseDate].CURRENTMEMBER.MEMBER_CAPTION
,NULL
,'not the same date'
)
SELECT
...
...
Related
I apologize if this has been covered somewhere, but I haven't found anything that quite meets my specific needs. In PeopleSoft Query Manager, we are trying to build a report that projects depreciation 5 or so years into the future. We want the columns to be the fiscal year and we want the returned values to be the annual depreciation by asset by business unit.
What we've tried so far is creating an aggregate expression that will sum the asset depreciation. This simple expression works in and of itself as it sums the monthly depreciation by asset. However, what we'd like to do is create 5+ columns with 5+ of these aggregate sum expressions, based on the fiscal year. So the first "numerical data" column would show 2019's depreciation, the second would show 2020's and so on.
Now, let me provide a disclaimer and say I'm an accountant and not a code person, so I'm less than a novice here. But we've tried embedding the aggregate sum function with case or decode and we have been unable to get it to work with any such conditional type functions. However, surely there must be a way? (For potential further clarity, if we had the data in excel we would use something like =SUMIFS(Depreciation column, fiscal year column, 2019) and then repeat that for the remaining years. We want to get this same result directly from the query though).
Below, we have two codes. The simple one that works but doesn't provide what we need exactly and the one with conditional functions that we can't quite get to work.
`SELECT A.BUSINESS_UNIT, A.ASSET_ID, sum( A.DEPR)
FROM PS_DEPR_RPT A
WHERE ( A.BOOK = 'CORPORATE'
AND A.BUSINESS_UNIT = '50226')
GROUP BY A.BUSINESS_UNIT, A.ASSET_ID
HAVING ( sum( A.DEPR) <> 0)`
`SELECT A.BUSINESS_UNIT, A.ASSET_ID, CASE
WHEN A.FISCAL_YEAR = 2019 THEN sum( A.DEPR)
END
FROM PS_DEPR_RPT A
WHERE ( A.BOOK = 'CORPORATE'
AND A.BUSINESS_UNIT = '50226')
GROUP BY A.BUSINESS_UNIT, A.ASSET_ID
HAVING ( CASE
WHEN A.FISCAL_YEAR = 2019 THEN sum( A.DEPR)
END <> 0)`
The first one works fine but does not have the necessary fiscal year information. Now, yes, we can use the fiscal year field as a criteria and then build an excel file using sumifs or other such formulas. But we really would like to not have to manipulate the data in excel, and it seems like we should be able to create this in PeopleSoft Query Manager.
Obviously, the second one looks off (I imagine people who are knowledgeable about SQL are banging their heads), and we get this error:
Error in running query because of SQL Error, Code=979, Message=ORA-00979: not a GROUP BY expression (50,380)
(In my preliminary research, it seems like the group by expression error was a common recurrence when using these conditional functions with aggregate functions).
Lastly, please keep in mind that I personally don't have the ability to create SQL that I could put into the system. The SQL is what query manager generates and my only ability to change it is by using expressions and criteria changes.
EDIT for current results and preferred results:
What It Looks Like As Is
What We Want It To Look Like
Thanks in advance!
Would much appreciate any help on this.
I have a measure called "Sales" populated with values, however i am trying to turn the "Sales" value to 0, whenever the "Sales Flag" is set to 0.
Important Note: The Sales Flag is based on Date (lowest level of detail).
The difficulty that i am really experiencing and cant get a grip on, is how i am trying the display the MDX outcome.
As explained above, i would want to make the "Sales" value 0 whenever we have a 0 in the "Sales Flag" (which is based on the Date), but when I run the MDX Script I would wan't on the ROWS to NOT display the Date, but instead just the Week (higher Level to Date), as below shows:
I really have spent hours on this and can't seem to understand how we can create this needed custom Sales measure based on the Sales Flag on the date level, but having the MDX outcome display ROWS on Week level.
Laz
You need to define the member in the MDX before the select. Something like that:
WITH MEMBER [Measures].[Fixed Sales] as IIF([Sales Flag].currentMember=1,[Sales], 0)
SELECT [Measures].[Fixed Sales] on 0, [Sales Flag] on 1 from [Cube]
I am writing the code without SSAS here so it might not be the 100% correct syntax but you can get the general idea ;)
You can add the iif in the SELECT part but I find creating member to be the cleaner solution.
SELECT IIF([Sales Flag].currentMember=1,[Sales], 0) on 0, [Sales Flag] on 1 from [Cube]
If you have a control over the cube in SSAS you can create a calculated member there and you can access it easier.
Glad to hear if Veselin's answer works for you, but if not...
Several approaches are also possible.
Use Measure expression for Sales measure:
Use SCOPE command for Day level (if it's Key level of Date dimension). If it's not a key level you have to aggregate on EVERY level (week, year etc) to emulate AggregateFunction of Sales measure but with updated behavior for one flag:
SCOPE([Date].[Your Date Hierarchy].[Day].members,[Measures].[Sales]);
THIS=IIF([Sales Flag].CurrentMember = 1,[Measures].[Sales],0);
END SCOPE;
Update logic in DSV to multiply Sales column by SalesFlag. This is the easiest way from T-SQL perspective.
I have a cube with few dimensions. Report Date and Account are two of them. One account id may come under multiple Report dates. I need to find minimum report date for every accountid. Any ideas?
Maybe something similar -
WITH SET[MinDate] AS
Head(NonEmpty(
ReportDate.[ReportDate].[ReportDate].MEMBERS,
{(EXISTING [Account].[AccountId].CurrentMember , [Measures].[foo])}
),1)
SELECT [MinDate] ON 1,
[Account].[AccountId].MEMBERS ON 0
FROM [bar]
WHERE [Measures].[foo]
If what you want is the minimum date's value, then you would need to get that in a calculated measure instead of a set.
WITH MEMBER Measures.[MinimumDate] AS
Head(NonEmpty(
ReportDate.[ReportDate].[ReportDate].MEMBERS,
{(EXISTING [Account].[AccountId].CurrentMember , [Measures].[foo])}
),1).ITEM(0).Name
I have a dimension [Date].[Last Met].
I need to pull out values which are more than 90 days from current date using MDX.
Please suggest the best way.
You can filter like this:
FILTER
(
[Date].[Last Met].MEMBERS,
Datediff("d",[Date].[Last Met].CurrentMember.Name, Format(Now(),'yyyyMMdd') <=90
)
A much more elegant option would be to create a calculated column in DSV called RollingLast90Days, and using SQL datediff logic to assign it 1/0. Once in place, you would need to just have a slicer :
...WHERE ([Time].[[RollingLast90Days].&[1])
Above is based on asumption you would process cube daily. If not apply the same logic in a calculated measure.
IIF(
Datediff("d",[Date].[Last Met].CurrentMember.Name, Format(Now(),'yyyyMMdd') <=90,
1,
null)
and then using this slicer on HAVING or in WHERE clause.
I have a fact table which stores for each record an init_year and end_year as integers, which refer to the year range in which the record is valid.
In which way I can design a MDX query to select my measures (count) for each year, in order to have a trend of my measures over year?
THANKS
I'm not sure this should be done in MDX.
This sort of thing is usually calculated in the fact tables (linked to a dimension table of all available years), and a new measure is created. No calculation would be done in MDX; you'd just display the new measure.
Having said that, I've just Googled "MDX count start end date" and found www.purplefrogsystems.com/blog/2013/04/mdx-between-start-date-and-end-date which suggests you use the LINKMEMBER function. Their example code was...
AGGREGATE(
{NULL:LINKMEMBER([DATE].[Calendar].CURRENTMEMBER
,[START DATE].[Calendar])}
* {LINKMEMBER([DATE].[Calendar].CURRENTMEMBER
, [END DATE].[Calendar]):NULL}
, [Measures].[Project COUNT])
...or...
AGGREGATE({NULL:[DATE].[Calendar].CURRENTMEMBER}
, [Measures].[Project COUNT])
...but it needs careful reading!