Sum-up and then calculate vs. calculate and then sum-up (SSAS-MDX) - ssas

I have a cube in SSAS multidimensional mode.
I have created a calculating measure in visual studio called "Total Cost". The formula is:
[Measures].[Unit Cost]*[Measures].[Qty]
It is in the lowest level of granularity (i.e. - the transnational level information has these fields).
The formula works well, as long as I present the data in this same level of granularity (for example, when I create a pivot and the rows are transaction IDs - like the source file)
However, when I present it in an aggregate format (for example - by customer) - then instead of making the calculation and then sum it up, it sum up and then calculate.
Here is what I expected:
Expected results vs. What I get
My understanding, that this is regardless a (correct/incorrect) hierarchy structure. In other words, I expected this calculation to work even without defining any hierarchy between the transaction ID level and the customer level.
I'd appreciate your help!

In your SSAS project ->datasource view, you need to add a named calculation. This would be "[Unit Cost]*[Qty]". Now add this named calculation as a Measure in your Cube. This do the job. This problem was already addressed in the following link.
https://stackoverflow.com/questions/53554284/how-to-multiply-two-measures-prior-to-aggregation/53558733#53558733

Related

MDX IIF statement to calculate new member basing on measure and hierarchy leaves

I have a simple Data Cube for computing shared expenditures with one measure Amount and some dimensions and hierarchies but interesting one would be Relationship. It describes who bought something for whom. It's structure is:
Who
For whom
Relationship key
I am trying to code a calculation representing debt. For example if I bought something for sharing usage it would be half of 0.5 * Amount. On the other hand, if I bought something for myself it would be 0 * Amount.
As far I tried following calculation:
IIF(
[dimRelationship].[Relationship].currentMember = [dimRelationship].[Relationship].[RelatonshipID].&[MeShared],
[Measures].[Amount]*0.5,
[Measures].[Amount]*0)
It works good only at lowest RelationshipID level. When I roll-up browsered pivot-table it is acting according to else-expression. That is not really surprising because hierarchy's currentMember is not MeShared anymore. Another bad thing that total aggregation work neither - it would be most important as a general summary. Is there any suffix like .LeafMember or something like that which could help me perform this calculation?
Thank you in advance!
Best regards,
Max!
In you fact table add another column, in this column store the "Amount" multiplied by the relationshipID for that particular row. This will address you issue right out the box
Try SCOPE statement.
Firstly, create new calculation [Debt Calculation] as [Measures].[Amount]*0 /* as ELSE-scenario */
Then create a SCOPE:
SCOPE([Debt Calculation],[dimRelationship].[Relationship].[RelatonshipID].&[MeShared]);
THIS=[Measures].[Amount]*0.5;
END SCOPE;
If it's the lowest level of hierarchy and is a dimension key (which is used as a link to measure groups), it will re-calc higher levels of this dimension automatically. Please post a result here if not.

SSAS OLAP Cube - Sum measure only works when keys are present

(This is a mock of my actual setup to help me figure out the problem.)
I have one fact table and one dimension table, linked by an id field.
My goal is to make a measure that sums up all "thing_count" (integer) values in my cube.
If the user splits by nothing, it should show the total "thing_count" for all records in the fact table. If it's split by "category_name" from the dimension, it should show the total "thing_count" for each category.
I tried to achieve this by creating a SUM measure in my cube:
It works, but not in the way I intend it to
It always shows (null) unless I drag in the "id" field from the dimension.
Measure only:
Measure and category:
Measure, category, and id:
How can I make the measure show the value without keys needing to be present?
Edit:
For GregGalloway's request (I've edited the names so the screenshots are easier to follow):
One common explanation for this behavior (no aggregation) is that you have inadvertently commented out the CALCULATE; statement in your MDX script in the cube. Please check that statement is still present.

How the aggregation and calculated members work as combined to produce output in SSAS Cube

I am creating a POC on the SSAS. Ultimate goal is to be able to perform any kind of the calculation either ad hoc calculation or pre calculated with good performance. Existing solutions is based on the SQL server but due to the performance issues with huge data facing issues.
I need some insight upon how the Cube works to give faster outputs. I have created date dimensions with hierarchy Year-> Semester-> Quarter -> Month -> Week -> Date. Several other dimensions are linked with the date dimension. My cube has almost 10 to 15 dimension which have several role playing dimensions.There are almost two to three dates in every fact table.
How the Cube aggregates the data based on the dimensions linked to the facts?
Does it internally creates all the combination of the dimension values and saves the fact aggregate data internally?
Here i have attached an MDX script which hase YTD,MTD,QTD Calculated Measures.[Measures].[Value] measure has to be added based on the function applied on the date dimension. Does SSAS internally sum up the [Measures].[Value] for various hierarchy of the date/Other dimension/s? What exactly SSAS does to provide the final value fast?
Our system has large number of the fields whose calculation depends on the value selected by the end user to the number has to be calculated at run time by aggregating some other measures. Does SSAS is fast to provide the Calcualted Member output by using the internally aggregated values generated during the cube processing?
With Member [Measures].[YTDValue] as ([Measures].[Value],
OpeningPeriod([Rundate].[Calendar].[Date],[Rundate].[Calendar].CurrentMember.Parent.Parent.Parent.Parent.Parent))
Member [Measures].[QTDValue]
as ([Measures].[Value],OpeningPeriod([Rundate].[Calendar].[Date],[Rundate].[Calendar].CurrentMember.Parent.Parent.Parent))
Member [Measures].[MTDValue]
as ([Measures].[Value],OpeningPeriod([Rundate].[Calendar].[Date],[Rundate].[Calendar].CurrentMember.Parent.Parent))
SELECT
{
[Measures].[YTDValue],
[Measures].[QTDValue],
[Measures].[MTDValue],
} on 0,
{
[Rundate].[Calendar].[Date].Members
} ON 1
FROM
(
select
{
[Rundate].[Calendar].[Date].&[2015-01-09T00:00:00]
} on 0
from [Cube_Sample]
)

SSAS Max calculation in cube

I have a dimension list of Product Codes and a measure called ACV in my cube. I need to be able to calculate the maximum ACV value for each product code.
I have got as far as the calculation below but that returns the sum of ACV for all products.
MAX([Products].[Product Code].[Product Code].Members, [Measures].[ACV])
I'd be grateful for input on how to resolve my problem.
Thanks!
If you want the maximum evaluated semiadditively by the grain of your model designed in the data source view, you should add a new measure (based on the same source field as the ACV measure) to your cube add set its AggregationFunction property to Max. More on aggregation functions in SSAS.

Access system tables in calculation

Is there a way to access system tables in a SSAS cube calcuation?
For example the following query can be executed on a SSAS cube to return a last processed date:
SELECT LAST_DATA_UPDATE FROM $System.MDSCHEMA_CUBES WHERE CUBE_NAME = 'Cube'
How would one access this information in a calculation?
Background: We were using ASSP before (a third party sproc) to get the last cube processed date. Recently, this sproc threw an exception on one of our cubes and caused SSAS to go down. Using the above line of MDX did not have this behavior. I would rather not have our cube depend on third party code so I am looking for a way to access LAST_DATA_UPDATE in a calc for a specific cube name.
I usually include a detached Dimension in my cubes e.g. ".Cube Information" which includes attributes like this. Other useful attributes could expose the currency of the data e.g. when did the last underlying ETL process complete, or the release/build of your cube.
I feed this "Cube Information" dimension from a SQL view which returns a single row with whatever data is needed - you could use your SELECT statement. It also needs to return a Key column with a fixed value e.g. 1.
By "detached" I mean the "Cube Information" dimension has no entries in the Cube Dimension Relationship tab.
In the cube Calculation script, I assign the DEFAULT_MEMBER property for that dimension to the fixed Key value from the SSAS view.
Any client tool can then access those Dimension attributes.