MDX: I need column count based on the total rows - ssas

Here we have total 14 rows, I need one more column (RowCount-Column name)
every-cell contains 14 (reputation) means total row counts.
below is the query
WITH MEMBER DimName AS [DimClinic].[Provider Key].CurrentMember.Member_Caption
MEMBER DimKey AS [DimClinic].[Provider Key].CurrentMember.Member_Key
SELECT {[Measures].DimKey ,
[Measures].DimName ,
[Measures].[DrPatientKeyCnt]} ON COLUMNS ,
NonEmpty([DimClinic].[Provider Key].[Provider Key])ON ROWS
FROM [PopulationReportCube]

WITH
MEMBER DimName AS
[DimClinic].[Provider Key].CurrentMember.Member_Caption
MEMBER DimKey AS
[DimClinic].[Provider Key].CurrentMember.Member_Key
MEMBER RowCount AS
Count
(
NonEmpty
(
[DimClinic].[Provider Key].[Provider Key]
,[Measures].[DrPatientKeyCnt]
)
)
SELECT
{
[Measures].DimKey
,[Measures].DimName
,[Measures].[DrPatientKeyCnt]
,[Measures].[RowCount]
} ON COLUMNS
,NonEmpty([DimClinic].[Provider Key].[Provider Key]) ON ROWS
FROM [PopulationReportCube];

Related

SSAS MDX - aggregate with multiple members

I have the MDX query below and the result is not what I expected. If my where clause is included just 1 city ([Geography].[Iorg].[City].[San Francisco]) then my aggregate result is correct for that city, but if Included 2 cities then my aggregate result is for the whole state of california which is not what I wanted. I just want to return result of those two cities.
{ [Geography].[Iorg].[City].[San Francisco]
,[Geography].[Iorg].[City].[San Jose]
}
This clause is for security {[Geography].[State].[California]} but I don't get when 1 city is included then the result is good but when I included two cities then the result is for state California.
If I remove my [Geography].[Country Name].children ON ROWS then the result is correct but I need that in my query. Any help would be appreciated.
SELECT
CROSSJOIN ({
[Measures].[Fleet]},
{[Time Calculations].[Current Period] }) ON COLUMNS
,
[Geography].[Country Name].children
ON ROWS
FROM [DMI]
WHERE
(
[Date].[Date Hierarchy].[Date].&[2019-02-12T00:00:00] ,
{ [Geography].[Iorg].[City].[San Francisco]
,[Geography].[Iorg].[City].[San Jose]
}
,{[Geography].[State].[California]}
)
You should query like this
SELECT
CROSSJOIN ({
[Measures].[Fleet]},
{[Time Calculations].[Current Period] }) ON COLUMNS
,
[Geography].[Country Name].children
ON ROWS
From (select {[Geography].[Iorg].[City].[San Francisco],
[Geography].[Iorg].[City].[San Jose]}on 1 FROM [DMI]
)
WHERE
(
[Date].[Date Hierarchy].[Date].&[2019-02-12T00:00:00]
,{[Geography].[State].[California]}
)

Multiply Dimension item with the numeric values

I have Dimension column as Price and the Measure column as Quantity, I want to multiply price with the quantity,Please help me write MDX.
I tried with the below query.
With Member [Measures].[A] As ([Part ID].[Price]), Format_String ='Number'
Member [Measures].[B] As [Measures].[Quantity] * [Measures].[A]
Select {[Measures].[A],[Measures].[B]} On Columns, NON EMPTY( [Part ID].[Part Id].Children ) On Rows from [studio_bomdata]
You just need the following change
With Member [Measures].[A] As ([Part ID].[Price].CurrentMember.Properties ("Member_Value",TYPED)
)

MDX query to except specific date from date range

I am need to delete all 2 month from set. This code return all date range without excepting 2 month.
SELECT
{[Measures].[In]} ON COLUMNS,
EXCEPT([Date].[2014].[1] : [Date].[2016].[2], [Date].[Month].[2]) ON ROWS
FROM [Shop hourly]
Print screen for whytheq
My decision based on whytheq answear. I create a dimension for all kind of dates, and except them. Example:
SELECT {[Measures].[In sum]} ON COLUMNS,
NON EMPTY
{[Shop].[11], [Shop].[22], [Shop].[33]} *
Except([Quarter].Children, [Quarter].[2]) *
[Month].Children ON ROWS
FROM [Shop hourly]
WHERE
([Date].[2013].[1].[1] : [Date].[2016].[1].[1]) *
Except([Year].Children, [Year].[2014])
In AdventureWorks I can do the following:
SELECT
[Measures].[Internet Sales Amount] ON 0
,NON EMPTY
Except
(
[Date].[Calendar].[Month].&[2005]&[7]
:
[Date].[Calendar].[Month].&[2008]&[7]
,Exists
(
[Date].[Calendar].[Month].MEMBERS
,[Date].[Calendar Quarter of Year].&[CY Q3]
)
) ON 1
FROM [Adventure Works];
So adapting the above to your cube maybe looks like the following:
SELECT
{[Measures].[In]} ON COLUMNS
,Except
(
[Date].[2014].[1] : [Date].[2016].[2]
,Exists
(
[Date].MEMBERS
,[Date].[Month].[2]
)
) ON ROWS
FROM [Shop hourly];

How can I get top 3 items sold in particular three days in MDX queries?

This is my MDX query. This will the items that is sold on particular three days. This query returns all items sold, but I wish to get only top 3 items on that particular dates.
How do I can get this? Here's my MDX query:
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER
(
(
[Products].[Item Description].children
),
[Measures].[Quantity], DESC
)
* [Calendar].[Date].[Date]
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
Use the TopCount function as below:
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
TopCount([Products].[Item Description].children * [Calendar].[Date].[Date],
3,
[Measures].[Quantity])
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
To get the top 3 records for each date, you can user the GENERATE function :
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
GENERATE([Calendar].[Date].[Date],
TopCount([Products].[Item Description].children,
3,
[Measures].[Quantity])
)
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])

need to get sum of all members of a dimension minus one member

I am trying to make an MDX query that can tell me how many products were sold in countries other than China. With the following query I can only get the units sold of bottled water for each of the countries, but not their sum. How do I modify the query to get the sum of that ?
SELECT NON EMPTY Except(
{[Location].[All Places].Children},
{[Location].[China]}
) ON COLUMNS,
{[Product].[All Products].[Bottled Water].Children} ON ROWS
FROM [Places]
WHERE [Measures].[Units Sold]
The following should do what you want:
WITH
SET [countries] as Except( {[Location].[All Places].Children}, {[Location].[China]} )
MEMBER [measures].[X] as Sum( [countries] , [Measures].[Units Sold] )
SELECT {[Product].[All Products].[Bottled Water].Children} ON ROWS
FROM [Places]
WHERE [measures].[x]