I would like to count all clients accounts in my cube. I have created new calculation and I wrote a query in MDX langugage like:
COUNT(
[Client].[IdClient]
)
but when I would like to know how many accounts have, I always get '1' value instead e.g. '6000'.
This is my first time with MDX and OLAP Cubes.
What I supposed to do to get correct value?
Try this:
COUNT(
EXISTING [Client].[IdClient].[IdClient].Members
)
If you aren't happy with the performance of that then delete the calculated measure and replace it with a measure group built on the Client table. Build a Count measure.
Related
I am a newb when it comes to MDX so please bear with me as I try to explain this.
I have cube with a measure for cost [Measure].[Cost] and the query is setup with a time parameter to obtain the total cost up to that point in time. #ToAcctDate and is used in the FROM statement as such:
FROM (SELECT (STROSET(#ToAcctDate, CONSTRAINED)) ON COLUMNS
but I would like to get the PREVIOUSMEMBER if possible and to something like
WITH
MEMBER [Measures].[PriorPeriod] AS
SUM( (STROSET(STROSET(#ToAcctDate, CONSTRAINED).PREVMEMBER), [Measures].[Cost])
so that I can then have both the YTD costs as of #ToAcctDate and the YTD Costs at the beginning of the period [Measures].[PriorPeriod] in the same query without unions. is this possible? and if so, is this the right approach?
Maybe along the lines of this?
HEAD will find the first member of the set which you can then apply PREVMEMBER to:
SUM(
HEAD(STROSET(#ToAcctDate, CONSTRAINED)).ITEM(0).ITEM(0).PREVMEMBER)
, [Measures].[Cost]
)
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!
This is a question regarding SSAS Cubes, MDX formulas and Power BI.
I have a measure with the active members per each month. So when I select for example 2018 it shouldn´t aggregate but return the last available month with active members, and if I break down by month it should give the active members for each month.
So I have this formula which works almost fine if querying in MS Management Studio:
with member [Measures].[Last existing SOCIOS] AS
Max(
EXISTING [DIM FECHA].[Jerarquía].[MES NOMBRE].members,
iif([Measures].[ACTIVOS] = 0,null,
[Measures].[ACTIVOS])
)
select {[Measures].[Last existing SOCIOS]} on columns,
[DIM FECHA].[MES NOMBRE].members on rows
from [cubo_Compromisos]
where [DIM FECHA].[AÑO].&[2018]
I would prefer to have the november value returned at the 'All' level. But this is not my main problem. The real issue is that when I use this measure in Power BI it behaves differently: when selecting multiple months it ignores the selected values and just returns the last value for the whole year.
In the screenshot below I have added the value returned by the KPI Card because that is the value that I want returned:
If I select items like this it does it right, but I need it to select all months, and not just one because I am using this measure along others:
Does anyone know the right MDX function to use or an alternative?
Edited: 23-11-2018
It does the same in a Pivot Table connected to a SSAS Cube.When I add the date dimension to the table it works fine. But when using the date dimension and filtering it without the dimension added as rows it returns the value for the whole year.
The function you are looking at is LastChild. Last Child on the upper level of the hierarchy will return the value you are looking at.
I think that function can be used in the Cube design in SSAS - then this will be the standard behavior. If you want to do it with a query you need to do something like:
SELECT [Date].[Fiscal].[Fiscal Quarter].[Q1 FY 2002].LastChild ON 0
FROM [Adventure Works]
To get the last month of the 1st quater (I used example from microsoft and another post on the subject )
For now sometimes I have problems with creating difficult calculated members in SSAS. Is it possible to make case which will SUM certain measure on certain level when user choose another certain level of dimension? For example we have standard time dimension with 4 levels:
Year
Month
Week
Day
Also we have some measure orders which have default function SUM in properties.
Which case do we need to calculate this: sum all orders in week which including current day which we have chosen already.
Also could you recommend me some nook or source for level up my mdx knowledge?
Thanks a lot.
Yes, it's possible, when you use MDX functions, which are connected with levels.
Here is an example with Year > Quarter > Month > Day hierarchy:
Use MDX calculated member to have a SUM of upper level member children (including selected one):
The same if you want to create calculation inside the cube:
CREATE MEMBER CURRENTCUBE.[Measures].[SameLevelMembers]
as SUM({[Report Date].[Report Date].CurrentMember.Parent.Children},[Measures].[Count]),
VISIBLE = 1 ;
And a result in cube browser:
Hundreds of articles you can find there: http://ssas-wiki.com/w/Articles#MDX
I also like this one: http://mdxpert.com because of well-structured info.
Im trying to create a daily calculation in my Cube or an MDX statement that will do a calculation daily and roll up to any dimension. I've been able to successfully get the values back, however the performance is not what I think it should be.
My fact table will have 4 dimensions 1 of which being daily date (time). I have a formula that uses 4 other measures in this fact table and those need to be calculated daily and then geometrically linked across the time dimension.
The following MDX statement works great and produces the correct value but it is very slow. I have tried using exp(sum(log+1))-1 and multiply seems to perform a little better but not good enough. Is there another approach to this solution or is there something wrong with my MDX statement?
I have tried defining aggregations For [Calendar_Date] and [Dim_Y].[Y ID], but it does not seem to use these aggregations.
WITH
MEMBER Measures.MyCustomCalc AS (
(
Measures.x -Measures.y
) -
(
Measures.z - Measures.j
)
)
/
Measures.x
MEMBER Measures.LinkedCalc AS ASSP.MULTIPLY(
[Dim_Date].[Calendar Date].Members,
Measures.MyCustomCalc + 1
) - 1
SELECT
Measures.LinkedCalc ON Columns,
[Dim_Y].[Y ID].Members ON Rows
FROM
[My DB]
The above query takes 7 seconds to run w/ the following number of records:
Measure: 98,160 records
Dim_Date: 5,479 records
Dim_Y: 42 records
We have assumed that by defining an aggregation that the amount of calculations we'd be performing would only be 42 * number of days, in this case a maximum of 5479 records.
Any help or suggestions would be greatly appreciated!