Using TopCount in MDX query - sharepoint

I'm trying to select the top 10 of a specified data set for use in a report. However, I'm not sure where it would go in the query. My current MDX query is below and mostly resembles what is automatically generated by the designer. What I'm trying to get is the top 10 Subcontractors by the value of Revised Value. Currently when I try to run this I get the error "Error running the data source query"
SELECT
TopCount([Dim Subcontractor].[Subcontractor Name].[Subcontractor Name].ALLMEMBERS, 10, [Measures].[Revised Value]),
{ [Dim Subcontractor].[Subcontractor Name].[Subcontractor Name].ALLMEMBERS }
ON COLUMNS,
{ [Measures].[Revised Value] }
ON ROWS
FROM [BGDEMO]
WHERE ( [Dim Project].[Project Name].DEFAULTMEMBER, [Dim Date].[Full Date].DEFAULTMEMBER )
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR
Any help with this is appreciated.

Figured it out. I'll post it here in case others might find it useful:
SELECT
{ TOPCOUNT([Dim Subcontractor].[Subcontractor Name].[Subcontractor Name],10, [Measures].[Revised Value]) }
ON COLUMNS,
{ [Measures].[Revised Value] }
ON ROWS
FROM [BGDEMO]
WHERE ( [Dim Project].[Project Name].DEFAULTMEMBER, [Dim Date].[Full Date].DEFAULTMEMBER )
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR

Related

Writing a subquery to display records in a grid

I have two DAC's POReceipt, and and POReceiptLine. POReceiptLine containts a field called MfrPartNbr.
I want the user to be able to lookup all the POReceipts where the POReceiptLine.MfrPartNbr is equal to an entered value.
The SQL would be
SELECT *
FROM dbo.POReceipt
WHERE POReceipt.ReceiptNbr IN
(
SELECT ReceiptNbr
FROM dbo.POReceiptLine
WHERE MfrPartNbr = 'MY_ENTERED_PART_NBR'
)
Any idea how to write the BQL Statement for this?
As stated, an inner join won't work in this case because you will receive the same POReceipt multiple times (once for each POReceiptLine). The following BQL query shows how you can get the desired results using a sub query. If mfrPartNbr is an extension field, then replace POReceiptLine.mfrPartNbr with the correct extension name (e.g. POReceiptLineExtension.mfrPartNbr).
PXSelect<POReceipt, Where<Exists<
Select<POReceiptLine,
Where<POReceiptLine.receiptNbr, Equal<POReceipt.receiptNbr>,
And<POReceiptLine.mfrPartNbr, Equal<Required<POReceiptLine.mfrPartNbr>>>>>>>>.Select(this, "MY_ENTERED_PART_NBR");

MDX Calculated Member displays no value in Excel but same query works in SSMS

I have a calculated member (not measure) of a dimension, which works in SSMS, but doesn't work in Excel 2013.
I've followed the advice described in this question on how to create calculated members.
So I have a new attribute in my lottery dimension called 'Relative Lotteries' with a single member 'All Lotteries in Scope' defined through the DSV.
I have a calculated member like this:
CREATE MEMBER CURRENTCUBE.[Lottery].[Relative Lotteries].[All].[This Lottery]
AS NULL, VISIBLE = 1;
Then a SCOPE Statement like this:
SCOPE ([Lottery].[Relative Lotteries].[All].[This Lottery]
,[Lottery].[Lottery Number].members);
THIS = 10000;--([Lottery].[Lottery Number].currentmember,measures.currentMember);
END SCOPE;
I've tried loads of combinations of SCOPE and THIS = , most of which work through SSMS but none work through Excel 2013.
I used OLAP extensions to get the MDX script generated by Excel 2013, The MDX is:
SELECT
{ [Measures].[Response - Sale Amt], [Measures].[Response - Qty of Orders] } DIMENSION PROPERTIES PARENT_UNIQUE_NAME
, HIERARCHY_UNIQUE_NAME ON COLUMNS
, NON EMPTY Hierarchize (
{
DrilldownLevel (
{ [Lottery].[Relative Lotteries].[All] }
,
,
, INCLUDE_CALC_MEMBERS
)
}
) DIMENSION PROPERTIES PARENT_UNIQUE_NAME
, HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Lottery]
WHERE ( [Lottery].[Lottery Number].&[141] ) CELL PROPERTIES VALUE
, FORMAT_STRING
, LANGUAGE
, BACK_COLOR
, FORE_COLOR
Through SSMS this query yields the expected result:
But through Excel 2013, I get this result:
The only thing I can think of is that its something to do with the Excel connection string. However its difficult to test. Excel won't let me remove or add any properties, it just returns the connection string back to how it was before editing. My Excel Connection string is:
Provider=MSOLAP.6;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Cube_Name;Data Source=ServerName;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error
I've been banging my head against a brick wall trying to work this out. Any ideas ???

MDX return fiscal PriorMTD date as value

I am trying to create MDX Calculated member which returns prior mtd date.
This is Calculated member I've created:
CREATE MEMBER CURRENTCUBE.[Measures].PriorMTDDate
AS cousin(
[Date].[Fiscal].CurrentMember,
[Date].[Fiscal].CurrentMember.parent.parent.lag(1)
),
VISIBLE = 1 ;
And this is query, but it returns just null:
select {[Measures].[PriorMTDDate]} on 0
from [WH_Cube]
WHERE ( [Date].[Fiscal].[Date].&[2014-09-12T00:00:00] )
Any idea what am I doing wrong?
EDIT: Another example returning null:
WITH MEMBER Measures.x AS
[Date].[Fiscal].CurrentMember
SELECT Measures.x ON 0
FROM [WH_Cube]
WHERE ( [Date].[Fiscal].[Date].&[2014-09-30T00:00:00] )
Does a measure need to be a numeric value?:
CREATE MEMBER CURRENTCUBE.[Measures].PriorMTDDate
AS cousin(
[Date].[Fiscal].CurrentMember,
[Date].[Fiscal].CurrentMember.parent.parent.lag(1)
).MemberValue ,
VISIBLE = 1 ;
.CurrentMember is evaluated at the row level, doesn't look into the slicer. The slicer is a global restriction on the cube, providing a sub-cube domain for your query.
In your query, [Date].[Fiscal].CurrentMember is underfined, as there is nothing on the Rows clause.
Try
select {[Measures].[PriorMTDDate]} on 0,
[Date].[Fiscal].[Date].&[2014-09-12T00:00:00] on 1
from [WH_Cube]

How to filter using calculated date value based on parameter in MDX

I'm trying to fetch the values based on a Date value passed as parameter (named AsOnDate) into a Performance Point report's MDX from a Webpart Date Filter. It's an Accounts database and the scenario is to fetch the Dormant accounts data. The problem I'm facing is that I need to fetch the Accounts having Dormant Date till 6 months before the AsOnDate value, i.e. AsOnDate -6 months, I managed to calculate the 6 month old date using DateAdd() function, like following:
DateAdd('m', -6, DateValue('<<AsOnDate>>'))
Now, I cann't figure out how to pass this value in place of the paramter in WHERE clause, MDX query looks like:
WITH
SET [Products] AS { <<Product>> }
MEMBER [Measures].[Dormant A/C Count] AS ([Measures].[Account Head Count])
MEMBER [Measures].[Dormant A/C Vol.] AS ([Measures].[LC Balance])
MEMBER [AH].[Subhead - Description].[Totals] AS Aggregate([Products])
SELECT
{ [Measures].[Dormant A/C Count], [Measures].[Dormant A/C Vol.]}
ON COLUMNS,
{[Products], [AH].[Subhead - Description].[Totals]}
ON ROWS
FROM
[MyCUbe]
WHERE (
[AH].[Is Dormant].&[1],
[AH].[Is Inoperative].&[0],
{NULL : [AH].[Dormant Date].&[ DateAdd('m', -6, DateValue('<<AsOnDate>>')) ]}
)
I get this error:
Error running data source query.
The 'DateAdd('m', -6, DateValue('2012-12-03'))'
string cannot be converted to the date type.
I have tried StrToMember() like:
WHERE (
[AH].[Is Dormant].&[1], [AH].[Is Inoperative].&[0],
{ NULL : StrToMember("[AH].[Dormant Date].&["+DateAdd('m', -6, DateValue('<<AsOnDate>>'))+"]")}
)
However, passing the Date Filter value directly as following works fine:
WHERE ( [AH].[Is Dormant].&[1], [AH].[Is Inoperative].&[0],
{ NULL : [AH].[Dormant Date].&[<<AsOnDate>>T00:00:00]} )
Figured it out, after some hit n trials.. managed to hack a combination of StrToMember() and Format() to convert calculated Date into string and feed it into MDX as Member, here's the working WHERE clause:
WHERE ( [AH].[Is Dormant].&[1], [AH].[Is Inoperative].&[0],
{ NULL : StrToMember("[AH].[Dormant Date].&[" + Format(DateAdd('m', -6, DateValue('<<AsOnDate>>')), 'yyyy-MM-dd') + "T00:00:00]") } )
Hope it will prove helpful for someone out there..

Grails: How do I create filter like the ones in MS Excel?

I want to sort the elements in my list and have the option of filter them the same way MS Excel does.
So it should be able to keep the filtered elements in the table and apply a filter within those results as well. Also be able to sort them without refreshing the whole table.
Any help is greatly appreciated!
you can do it with a criteria in you list action of your controller
def result
if ( params?.filter && params?.filterVal) {
result = Book.createCriteria().list(max: params?.max, offset: params?.offset) {
eq(params?.filter,params?.filterVal)
}
} else {
// normal list retrieval code
}
where params?.filter is the property to filter on and params?.filterVal is the value

Resources