I am trying to overwrite the value of the member [Balance to Total] in two attributes using SCOPE. However, when I view the results in Excel they both have a value of 4. Why aren't they showing different values?
SCOPE ([Measures].allmembers);
[Group].[Attribute1].&[Balance to Total] = 2;
[Group].[Attribute2].&[Balance to Total] = 4;
END SCOPE;
I think that the FREEZE function solves my problem.
Related
I'm trying to create a calculated column indicating if a team has a prize or not from the table below:
To do that I need to count within the group if there's a player whose "Prize" field is not empty. Here's the 1st attempt:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,len(Table4[Prize])>0)),Player_Same_Team)>0
Looks like it's going what I intend it to do. However, when I swap the filter content to a pre-defined variable, it gave me results that don't make sense:
Dax Formula:
=
Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = len(Table4[Prize])>0
Return
calculate(countrows(filter(Table4,Has_Prize)),Player_Same_Team)>0
The typed content len(Table4[Prize])>0 is the same as that in the variable, so what may be causing the difference? Thanks for your help.
As soon as you assign it to a variable, the value of the variable remains constant. Therefore the Len is evaluated to a value, that you are then passing as a filter.
The first example works because the CALCULATE accepts a table as a parameter, and player_same_team is evaluated to a table, by using the FILTER expression.
In order for what you are trying to do to work it would have to be something like this:
= Var Player_Same_Team = filter(Table4,Table4[Team]=earlier(Table4[Team]))
Var Has_Prize = filter(Table4,len(Table4[Prize])>0)
Return calculate(countrows(Has_Prize),Player_Same_Team)>0
You can also write the measure in a slightly different way:
= CALCULATE ( COUNT(Table4[Team]),
ALLEXCEPT(Table4[Team]),
LEN(Table4[Prize])>0) > 0
I would like to compute a value (number) which should be presented in a column (https://github.com/olifolkerd/tabulator).
I know the way of "mutation" which has the downside of manipulating the objects.
Another approach would be "formatting" which has downside that the result is of type string and other feature like sorting and sum etc. are not available.
So the question is: is there a way to compute a value ?
You can use the cellEdited callback and add a function that calculates the values.
sample function:
var mcalcHour=function(cell){
var rdata=cell._cell.row.data;
rdata.rc_total = (rdata.hourly_rate * rdata.hours);
}
I have an MDX query
IIF
(
IsLeaf([PnL].[PnL_A].CurrentMember)
,
[Measures].[PnL - Plan] * [PnL].[Flag 5].CurrentMember.MemberValue
,Sum
(
[PnL].[PnL_A].CurrentMember.Children
,[Measures].[PnL- Plan (signed)]
)
)
What it does:
The whole thing represents profit and loss. Unfortunately, it is constructed in a way that there are two columns: value of a profit or loss, and flag in the other column.
So if the flag ([PnL].[Flag 5]) is set to -1, the value ([Measures].[PnL - Plan]) is a loss, if the flag is a 1 - the value is a profit. I can't change that.
The query finds leaves of the hierarchy (single deepest source of a profit or loss) and multiplies the flag with the value. For non-leaf members it just aggregates it's leaves.
My problem is that it works too slow - I wanted to rewrite this query using SCOPE but I have no idea how.
Since I have absolutely no idea on your cube structure, let's say your member structure is
Pnl-->Pnl_A-->NonLeaf-->Leaf
You could define scope as below -
CREATE MEMBER CurrentCube.[Measures].[ProfitOrLossValue] AS NULL;
//Current member is leaf and Flag5 is 1
SCOPE
(
[Measures].[ProfitOrLossValue],
[PnL].[Flag 5].&[1],
[PnL].[PnL_A].[Leaf].[All].CHILDREN
);
This = [Measures].[PnL - Plan];
END SCOPE;
SCOPE
(
[Measures].[ProfitOrLossValue],
[PnL].[Flag 5].&[-1],
[PnL].[PnL_A].[Leaf].[All].CHILDREN
);
This = ([Measures].[PnL - Plan] * -1);
END SCOPE;
//Current member is non-leaf
SCOPE
(
[Measures].[ProfitOrLossValue],
[PnL].[PnL_A].[NonLeaf].[All].CHILDREN
);
This = Sum
(
[PnL].[PnL_A].CurrentMember.Children,
[Measures].[PnL- Plan (signed)]
);
END SCOPE;
Hope it helps.
I have some MDX in my SSAS cube something like:
CREATE MEMBER CURRENTCUBE.[Measures].[xx] AS 1;
SCOPE ([Measures].[xx]);
SCOPE ([Measures].[xx], [DimA].[DimA Hierarchy].Members);
This= 20;
END SCOPE;
SCOPE ([Measures].[xx], [DimB].[DimB Hierarchy].Members);
This= 2;
END SCOPE;
END SCOPE;
Browsing the cube and selecting the [xx] measure always returns 2, no matter if I use the DimA, DimB or no dimensions at all.
If I swap the order of the inner scope declrations, (ie DimB's scope before DimA's) I get 20 no matter what.
Clearly I'm doing something wrong??
SCOPE only makes sense if you use it on a subset of the members of a hierarchy.
[DimB].[DimB Hierarchy].Members and [DimA].[DimA Hierarchy].Members have no effect in scope, as they refer to all members of the hierarchy. Hence, one of these is always the current member, and the last scope always is used. Except you define a calculated member on that hierarchy, and it is the current member.
You probably want at least to exclude the All member, so that the SCOPE is only used for other members that this member, which is by default the current member if you do not use the hierarchy at all. In case DimA Hierarchy is an attribute hierarchy and not a user hierarchy, you can use [DimA].[DimA Hierarchy].[DimA Hierarchy].Members to get the members of the DimA Hierarchy level, which are all members except the All member.
Try something like this:
CREATE MEMBER CURRENTCUBE.[Measures].[xx] AS 1;
SCOPE ([Measures].[xx]);
SCOPE ([DimA].[DimA Hierarchy].Members);
This= 20;
END SCOPE;
SCOPE ([DimB].[DimB Hierarchy].Members);
This= 2;
END SCOPE;
END SCOPE;
I'm trying to create a calculated member measure for a subset of a group of locations. All other members should be null. I can limit the scope but then in the client (excel in this case) the measure does not present the grand total ([Group].[Group].[All]).
CREATE MEMBER CURRENTCUBE.[Measures].[Calculated Measure]
AS (
Null
),
FORMAT_STRING = "$#,##0.00;-$#,##0.00",
NON_EMPTY_BEHAVIOR = { [Measures].[Places] }
,VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Locations';
-----------------------------------------------------------------------------------------
SCOPE ({([Group].[Group].&[location 1]),
([Group].[Group].&[location 2]),
([Group].[Group].&[location 3]),
([Group].[Group].&[location 4]),
([Group].[Group].&[location 5])
}, [Measures].[Calculated Measure]);
// Location Calculations
THIS = (
[Measures].[Adjusted Dollars] - [Measures].[Adjusted Dollars by Component] + [Measures].[Adjusted OS Dollars]
);
END SCOPE;
It's as though the [Group].[Group].[All] member is outside of the scope so it won't aggregate the rest of the members. Any help would be appreciated.
Your calculation is applied after all calculations already happened. You can get around this by adding Root([Time]) to the scope, assuming your time dimension is named [Time]. And if you want to aggregate across more dimensions, you would have to add them all to the SCOPE.
In most cases when you have a calculation that you want too do before aggregation it is more easy to define the calculation e. g. in the DSV, e. g. with an expression like
CASE WHEN group_location in(1, 2, 3, 4) THEN
Adjusted_dollars - adjusted_dollars_by_comp + adjusted_os_dollars
ELSE NULL
END
and just make a standard aggregatable measure from it.
I've searched high and low for this answer. After reading the above suggestion, I came up with this:
Calculate the measure in a column in the source view table
(isnull(a,0) - isnull(b,0)) + isnull(c,0) = x
Add the unfiltered calculated column (x) to the dsv
Create a named calculation in the dsv that uses a case statement to filter the original calc measure CASE WHEN location IN ( 1,2,3)THEN xELSE NULLEND
Add the named calculation as measure
I choose to do it this way to capture the measure unfiltered first then, if another filter needs to be added or one needs to be taken off, I can do so without messing with the views again. I just add the new member to filter by to my named calculation case statement. I tried to insert the calculation directly into a named calculation in the dsv that filtered it as well but the calculation produced the incorrect results.