I created a hierarchies like this photo below:
http://i.stack.imgur.com/ErOXQ.png
On MDX query
Select [AccSetting].[UserN].[UserN] ON 1
FROM [Olap_report]
Where [AccSetting].[AgID].[115]
This query return all UserN are children of AgID 115. but I want to return exactly UserN of AgID =115?
Think I understand now - the name is is a property of the member.
Create a custom measure that returns the property.
WITH
MEMBER [Measures].[NameColumn] AS
[AccSetting].[AgID].CURRENTMEMBER.Member_Name
MEMBER [Measures].[NameColumn2] AS
[AccSetting].[AgID].CURRENTMEMBER.Name
SELECT
{
[Measures].[NameColumn]
,[Measures].[NameColumn2]
} ON 0,
[AccSetting].[AgID].[115] ON 1
FROM [Olap_report]
Reference to msdn:
https://msdn.microsoft.com/en-us/library/ms145583.aspx
Edit
First check the member exists:
SELECT
{
[Measures].[<add measure here>],
[Measures].[<add measure here>]
} ON 0,
{
[AccSetting].[AgID].[115],
[AccSetting].[AgID].[113]
} ON 1
FROM [Olap_report]
Related
I have this query:
public static function totalByAgent(int $agentId)
{
return PropertyListing::select(
DB::raw('SUM(property_listing.rental) as rental'),
DB::raw('SUM(property_listing.sale) as sale'),
'property_category.name as category_name',
'property_category.id as category_id'
)->join(
'property_category',
'property_category.id',
'property_listing.category_id'
)->where('agent_id', $agentId)->groupBy('property_category.id')->get();
}
With this query I obtain the sum of properties for sale and sum of properties to rent group by property categories. But If some property have only properties for sale and 0 to rent I obtain 0 in sum of rents.
I tried adding:
->having('sale', '>', 0)->get()
after groupBy. this hides the rents if they had.
Any idea?
Best regards
Finally this query works for me:
return Property::published()->select(DB::raw('SUM(property.rental) as rental'),
DB::raw('SUM(property.sale) as sale'),
'property_category.name as category_name',
'property_category.id as category_id')
->join('property_category', 'property_category.id', 'property.category_id')
->whereExists(function ($query) use ($agentId){
$query->select('property_listing.agent_id')
->from('property_listing')
->whereRaw('property.id = property_listing.property_id')
->where('property_listing.agent_id', $agentId);
})->published()
->groupBy('property_category.id')->get();
I have an MDX query like;
with
set [IcPiyasaCC] as
{
[DimCostCenterView].[CostCenterKey].&[S_EDT],
[DimCostCenterView].[CostCenterKey].&[S_END.MRG],
[DimCostCenterView].[CostCenterKey].&[S_GM_YRD],
[DimCostCenterView].[CostCenterKey].&[S_PER.RAF],
[DimCostCenterView].[CostCenterKey].&[S_ULUSAL],
[DimCostCenterView].[CostCenterKey].&[S_PAS_MARG]
}
member [DimCostCenterView].[CostCenterKey].[IcPiyasa] as
aggregate([IcPiyasaCC])
SELECT
NON EMPTY
{
[Measures].[Fiili_TutarTonaj]
} ON COLUMNS,
NON EMPTY
{
(
[DimCostCenterView].[CostCenterKey].[IcPiyasa]
--*[DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS
)
}
ON ROWS
and I can get desired output like;
- Fiili_TutarTonaj
IcPiyasa 6
But when I try to cross join with [DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS which is on same hierarchy, to get if any related "CostCenterKey"s , I get "CostCenterKey hierarchy is used more than once in the Crossjoin function." error message. How can I crossjoin them to get result like;
- - Fiili_TutarTonaj
IcPiyasa S_EDT 1
IcPiyasa S_END.MRG 2
IcPiyasa S_ULUSAL 3
Thanks.
You can host the new aggregated member in a different hierarchy. The cross-join will then be possible:
WITH
SET [IcPiyasaCC] AS
{
[DimCostCenterView].[CostCenterKey].&[S_EDT],
[DimCostCenterView].[CostCenterKey].&[S_END.MRG],
[DimCostCenterView].[CostCenterKey].&[S_GM_YRD],
[DimCostCenterView].[CostCenterKey].&[S_PER.RAF],
[DimCostCenterView].[CostCenterKey].&[S_ULUSAL],
[DimCostCenterView].[CostCenterKey].&[S_PAS_MARG]
}
MEMBER [Geography].[Geography].[All].[IcPiyasa] AS
AGGREGATE(
[IcPiyasaCC],
([Geography].[Geography].[All])
)
SELECT
NON EMPTY
[Measures].[Fiili_TutarTonaj] ON 0,
NON EMPTY
[Geography].[Geography].[All].[IcPiyasa]
*[DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS
ON 1
...
...
Or this:
WITH
SET [IcPiyasaCC] AS
{
[DimCostCenterView].[CostCenterKey].&[S_EDT],
[DimCostCenterView].[CostCenterKey].&[S_END.MRG],
[DimCostCenterView].[CostCenterKey].&[S_GM_YRD],
[DimCostCenterView].[CostCenterKey].&[S_PER.RAF],
[DimCostCenterView].[CostCenterKey].&[S_ULUSAL],
[DimCostCenterView].[CostCenterKey].&[S_PAS_MARG]
}
MEMBER [Measures].[ForceName] AS 'IcPiyasaCC'
MEMBER [Geography].[Geography].[All].[IcPiyasa] AS
(
[Geography].[Geography].[All]
,[Measures].[ForceName]
)
SELECT
NON EMPTY
[Measures].[Fiili_TutarTonaj] ON 0,
NON EMPTY
[Geography].[Geography].[All].[IcPiyasa]
*[DimCostCenterView].[CostCenterKey].[CostCenterKey].ALLMEMBERS
ON 1
Here is my MDX query below:
SELECT
{
[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON COLUMNS
,NonEmpty([AccSetting].[User N].[User N] * [Cur Log].[Cur Log ID].Children) ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
http://i.stack.imgur.com/0yDHg.png
UserID =113 is a hierarchies and a want to get the userN of it
I want to return exactly UserName of UserID =113 on Rows. but I'm not sure how to do it.
If you just want the name and nothing else then this should do it:
SELECT
{} ON COLUMNS
,[AccSetting].[User N].[User N] ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
If you want to turn the name into a measure then something like the following, with a custom measure should help:
WITH
MEMBER [Measures].[userName] AS
[AccSetting].[User N].CurrentMember.Member_Caption
SELECT
{} ON 0
,{
[Measures].[userName]
,[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON 1
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
To return the columns you mentioned in comment this should work:
SELECT
NON EMPTY
{
[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON COLUMNS
,NON EMPTY
[AccSetting].[User N].[User N].MEMBERS
* [Cur Log].[Cur Log ID].MEMBERS
ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
EDIT
Answer in this article:
Get hierarchies valuesName mdx
Try having this way:
with dynamic set UserN as
NonEmpty(
[AccSetting].[User N].[User N].members * [Cur Log].[Cur Log ID].Children
,
[AccSetting].[Ag ID].currentmember
*
{
[Measures].[Amt Exrate],
[Measures].[Comm Exrate]
}
)
SELECT
{
[Measures].[Amt Exrate]
,[Measures].[Comm Exrate]
} ON COLUMNS
,UserN ON ROWS
FROM [report]
WHERE
[AccSetting].[Ag ID].&[113];
Really stuck with Linq to SQL grouping and summing, have searched everywhere but I don't understand enough to apply other solutions to my own.
I have a view in my database called view_ProjectTimeSummary, this has the following fields:
string_UserDescription
string_ProjectDescription
datetime_Date
double_Hours
I have a method which accepts a to and from date parameter and first creates this List<>:
List<view_UserTimeSummary> view_UserTimeSummaryToReturn =
(from linqtable_UserTimeSummaryView
in datacontext_UserTimeSummary.GetTable<view_UserTimeSummary>()
where linqtable_UserTimeSummaryView.datetime_Week <= datetime_To
&& linqtable_UserTimeSummaryView.datetime_Week >= datetime_From
select linqtable_UserTimeSummaryView).ToList<view_UserTimeSummary>();
Before returning the List (to be used as a datasource for a datagridview) I filter the string_UserDescription field using a parameter of the same name:
if (string_UserDescription != "")
{
view_UserTimeSummaryToReturn =
(from c in view_UserTimeSummaryToReturn
where c.string_UserDescription == string_UserDescription
select c).ToList<view_UserTimeSummary>();
}
return view_UserTimeSummaryToReturn;
How do I manipulate the resulting List<> to show the sum of the field double_Hours for that user and project between the to and from date parameters (and not separate entries for each date)?
e.g. a List<> with the following fields:
string_UserDescription
string_ProjectDescription
double_SumOfHoursBetweenToAndFromDate
Am I right that this would mean I would have to return a different type of List<> (since it has less fields than the view_UserTimeSummary)?
I have read that to get the sum it's something like 'group / by / into b' but don't understand how this syntax works from looking at other solutions... Can someone please help me?
Thanks
Steve
Start out by defining a class to hold the result:
public class GroupedRow
{
public string UserDescription {get;set;}
public string ProjectDescription {get;set;}
public double SumOfHoursBetweenToAndFromDate {get;set;}
}
Since you've already applied filtering, the only thing left to do is group.
List<GroupedRow> result =
(
from row in source
group row by new { row.UserDescription, row.ProjectDescription } into g
select new GroupedRow()
{
UserDescription = g.Key.UserDescription,
ProjectDescription = g.Key.ProjectDescription,
SumOfHoursBetweenToAndFromDate = g.Sum(x => x.Hours)
}
).ToList();
(or the other syntax)
List<GroupedRow> result = source
.GroupBy(row => new {row.UserDescription, row.ProjectDescription })
.Select(g => new GroupedRow()
{
UserDescription = g.Key.UserDescription,
ProjectDescription = g.Key.ProjectDescription,
SumOfHoursBetweenToAndFromDate = g.Sum(x => x.Hours)
})
.ToList();
I am attempting to implement paging to large datasets in MDX (SSAS).
I have the following to retrieve paged data which works fine:
SELECT
{
[Measures].[Mesasure1],
[Measures].[Measure2]
} ON COLUMNS,
SUBSET
(
ORDER
(
{
(
[Item].[Category].ALLMEMBERS
)
}, NULL, BASC
), 10, 50 --10 = start index, 50 = returned roes
)
ON ROWS
FROM ( SELECT ( { [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] } ) ON COLUMNS
FROM [DataMartPerformance]
))
However I cannot for the life of me find anywhere on the internet that helps explain how to get the total rows available. Do I do it in a seperate query? If so how?
Or can I wrap it into this one query somehow?
Similar to how you'd do TSQL paging, you'll need to run another query to count the total elements. You may have to tinker with this depending on how you've done your original query, but I use something like:
WITH
MEMBER [Measures].[ElementCount] AS
{
NONEMPTY
(
{
[Item].[Category].ALLMEMBERS *
{ [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] }
},
{
[Measures].[Mesasure1],
[Measures].[Measure2]
}
)
}.COUNT
SELECT
{
[Measures].[ElementCount]
}
ON COLUMNS
FROM
[DataMartPerformance]
For filtering, you can do dimension filters by using an exists against your dimension attributes:
WITH
MEMBER [Measures].[ElementCount] AS
{
NONEMPTY
(
EXISTS
(
{
[Item].[Category].ALLMEMBERS *
{ [Time].[Date].&[2012-04-15T00:00:00]:[Time].[Date].&[2012-04-20T00:00:00] }
},
{
[Dimension].[Attribute].[FilterByThisAttribute]
}
),
{
[Measures].[Mesasure1],
[Measures].[Measure2]
}
)
}.COUNT
SELECT
{
[Measures].[ElementCount]
}
ON COLUMNS
FROM
[DataMartPerformance]
I haven't got to writing the measure value filters yet, I need to do that next for my own MDX paging constructor...
Please try this:
WITH
SET MySet As
(
NONEMPTY (
[AU Time Sale Hour].[Hour Key].[Hour Key]
* [Dim Country].[Country Key].[Country Key]
)
)
Member [Measures] .cnt AS MySet.Count
select [Measures] .cnt on Columns
from [Me Stats DW Fact Sales]
where (
{[Dim Visa].[Visa Key].&[2067],[Dim Visa].[Visa Key].&[2068] },
[AU Time Sale Date].[Date].&[20091120]:[AU Time Sale Date].[Date].&[20091125]
)