I need your help with a scope definition where the Goal is to create (in this case) a site = "TAI API", that is the aggregation of two other sites
"CPH API" + "US API" where product
in ([Product].[Manufacturing Family].&[BANT],[Product].[Manufacturing Family].&[BZNT],[Product].[Manufacturing Family].&[VANT]))
What I have done is creating the site as follow:
CREATE MEMBER CURRENTCUBE.[Order Company Group].[Parent].[All].[TAI API]
as [Order Company Group].[Parent].&[10440 - API]+[Order Company Group].[Parent].&[10240 - API]
, VISIBLE = 1 ;
Then I would like to define a scope for this site "TAI API", so that it works for any measure, but I am unsure what the next step is... I have tried something like this, but it doesn't work as intended:
SCOPE ([Order Company Group].[Parent].[All].[TAI API] ) ;<br/>
this = ([Measures].??<br/>
,([Product].[Manufacturing Family].&[BANT],[Product].[Manufacturing Family].&[BZNT],[Product].[Manufacturing Family].&[VANT]));<br/><br/>
END SCOPE;
The [Measures].?? is to indicate that I am not sure if this is needed or what to write...
Turns out I can do something like this
CREATE MEMBER CURRENTCUBE.[Order Company Group].[Parent].[All].[TAI API]
as [Order Company Group].[Parent].&[10440 - API]+[Order Company Group].[Parent].&[10240 - API]
, VISIBLE = 1 ;<br/><br/>
SCOPE ([Order Company Group].[Parent].[All].[TAI API]);<br/>
SCOPE([Product].[Manufacturing Family].[Manufacturing Family].members
- [Product].[Manufacturing Family].&[BANT]
- [Product].[Manufacturing Family].&[BZNT]
- [Product].[Manufacturing Family].&[VANT]
);<br/>
this = null;
<br/>
END SCOPE;
<br/><br/>
END SCOPE;
Thanks Thomas
You can use scope w/o any measures references:
At the very beginning (I just used my own DB with sample on standard Year-Month-Day dimension):
CREATE MEMBER CURRENTCUBE.[Create Date].[Create Date].[Month].&[201402].[20140200]
AS null,
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Data' ;
And than scope at the end:
SCOPE ([Create Date].[Create Date].[Month].&[201402].[20140200]);
THIS = SUM({[Create Date].[Create Date].[Day].&[20140214],[Create Date].[Create Date].[Day].&[20140228]});
END SCOPE;
This will work even with calculated measures with Descendants (e.g. ...Exists(Descendants([Create Date].[Create Date].[Year].&[2014],[Create Date].[Create Date].[Month],SELF_BEFORE_AFTER)...)
Please see this image. Is it expected result?
If so, you can just set first time NULL to this new member. And that in scope write
SUM([Order Company Group].[Parent].&[10440 - API],[Order Company Group].[Parent].&[10240 - API])
Hope it helps.
Related
I am using Active Admin in my multi tenant app. I also use Searchkick which has a custom tenant specific index in each model:
class Budget < ApplicationRecord
multi_tenant :company
searchkick inheritance: true,index_name: -> { [MultiTenant.current_tenant.tenant_name, model_name.plural, Rails.env].join('_') }
end
The issue is that in AA this logic fails because on the tenant is set. I want to be able to set this in AA when updating a record.
For example I would update http://localhost:4000/admin/budgets/dt2kqvgm where dt2kqvgm is the Friendly ID of the record. So I want to call something like:
MultiTenant.current_tenant = Budget.friendly.find(params['budget']['company_id'])
when I create / update a record etc.
Currently I get:
undefined method `tenant_name' for nil:NilClass
because in my application controller the tenant is set based on the user authentication to scope the current company etc. In AA I want/ need to set this based on the params which it seems you can't access from the AA controller logic. My params look like this in AA:
{"utf8"=>"✓", "_method"=>"patch", "authenticity_token"=>"PrhNGnPvV1Qfb5RCwTVv4Wwz9tjf9SFy2VWDcyJXoFLytM8y5ZAyF7h8I7xa+fy01E9Fc/v2CvR52I4/LKOLHQ==", "budget"=>{"company_id"=>"9", "name"=>"qweqwe", "description"=>"qweqwe", "notes"=>"qwee", "flag_active"=>"1", "slug"=>"dt2kqvgm", "title"=>"qweqwe"}, "commit"=>"Update Budget", "controller"=>"admin/budgets", "action"=>"update", "id"=>"dt2kqvgm"}
I don't know if this is the best way to do this but it works. I am know it needs tweaks but it's a start - you needs to:
set an around_action filter
add permitted_params
around_action :set_tenant, only: :update
controller do
def set_tenant
MultiTenant.with(Company.find(resource.company_id)) do
yield
end
end
def permitted_params
params.permit location: %[ company_id ]
end
end
It would seem this is required for each controller. Perhaps there is a way to add this as a default AA filter?
I also added the filter to just the update action.
I have been on this issue for the past 2 weeks and am getting bored of MDX and my work.
I have a scope script to override the figure coming from the source table for the following lines. 1. Pool Charge (2075) 2. Pool Compensation (2076)
SCOPE ([Measures].[Income Amount]);
SCOPE ([Income Caption].[Captions].&[2075],[Measures].[Income Amount]); //POOL CHARGE
this = [Measures].[Charge];
END SCOPE;
SCOPE ([Income Caption].[Captions].&[2076],[Measures].[Income Amount]); // POOL COMPENSATION
this = [Measures].[Compensation];
END SCOPE;
Screenshot of the sample reports.
I want to further manipulate those 2 lines in green: I want to sum-up other Pool Contribution entries and place it in MD LINE. Please note MDLine exclusive. The same goes to Pool Charge.
MD LINE Pool compensation = 'ASSET & INVESTMENT MANAGEMENT' + 'CORPORATE BANKING' + 'GENERAL DEFAULT' + 'INVESTMENT BANKING' + 'TREASURY AND GLOBAL MARKETS' Please note only Pool compensations and Pool charges.
All efforts been returning null or #VALUE.
Please help.
Many thanks.
What about?
Scope ([Income Caption].[Captions].&[2075],[Measures].[Income Amount]);
This = IIF(
[Something].[Something].CurrentMember is [Something].[Something].[MD LINE]
([Something].[Something].[All],[Measures].[Charge]),
[Measures].[Charge]
);
End Scope;
Replace Something with the corresponding dimension and hierarchy.
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 am very new to CRM development, i was trying to follow this article, i am a bit confused about below code, please check:
var xp = Xrm.Page;
function onLoad(context) {
var accountId = xp.data.entity.getId();
var mostRecentQuery = "/XRMServices/2011/organizationData.svc/ContactSet?
$select=FullName,JobTitle,EMailAddress1,Telephone1&$top=1&$orderby=CreatedOn
desc&$filter=ParentCustomerId/Id eq guid'" + accountId + "'";
getContact(mostRecentQuery, "MostRecent");
....
}
The above javascript function executes when AccountForm is opened. The first line gets the accountId. the next line is oData query.
Now check the ContactSet in this query, i am confused here, how we can retrieve the ContactEntity based on the GUID of AccountEntity?
I found the answer!
Actually there a Lookup 'Parent Customer' on ContactEntity, it represents the unique identifier of the account or contact associated with this contact, so we can select an Account/Contact as the Parent Customer of a contact.
So this given OData query actually retrieves the top 1 contact where this account is referenced.
I hope its clear.