If I use the following Negative total instead of previous one i am getting the same output but still not my expected output. Is there anyone to help me out?
MEMBER [Measures].[Negative Total] AS
CASE
WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) < 0
THEN [Measures].[Total]*-1
WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) > 0
THEN 0
END
Let me explain what I am trying to achieve. I have a Dimension of [Dim Account] which has the attributes like [Account Type],[Account Activity], [Account Marketing] etc. [Account Type] is income, expense,.. [Account Activity] is like Advertising,Discounts, Sale of sponsorship,etc [Account Marketing] is the combination of those things I mean advertising is the expense whereas discounts is stored as the negative income, so ultimately discounts will be treated as marketing expense That's why my member [Negative Total] is converting the income multiplied by -1 and i want to exclude those income are positive as they are income. I want to display only those converted income and finally add up them. In my MDX, the data are displayed perfectly but added up the original value -43380.4 +18 - 9181.32= -52542.81 that was supposed to be 43380.4 +0 +9181.32= 52561.72. For comparing the original total with expected total I displayed [Measure].[Total] and [Measure].[Negative Total] concurrently. Help me please if you know the trick
WITH
MEMBER [Measures].[Negative Total] AS
CASE
WHEN
[Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
[Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
[Measures].[Total]<1
THEN [Measures].[Total]*-1
WHEN
[Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
[Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
[Measures].[Total]>1
THEN 0
END
SELECT
{
[Measures].[Total],[Measures].[Negative Total]} on COLUMNS
,
NON EMPTY
(
{
(
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
*
{
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
VISUALTOTALS([Dim Account].[Account Activity].[All])
}
)
}
,
[Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire] ,
[Dim Scenario].[Scenario Name].&[Actual] ,
[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
)
on ROWS
FROM [CubeProfitLoss]
It is working as expected since [All] too is a member.
To achieve what you want, add a base measure that gets the negative total and then use it in the final calculation.
MEMBER [Measures].[Negative Total Test] AS
CASE
WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) < 0
THEN [Measures].[Total]*-1
WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) > 0
THEN 0
END
MEMBER [Measures].[Negative Total] AS
CASE
WHEN [Dim Account].[Account Activity].CURRENTMEMBER IS [Dim Account].[Account Activity].[All]
SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
ELSE [Measures].[Negative Total Test]
END
(Just to add to Sourav's nice solution)
CASE and IIF are both slow - IIF can be faster in some circumstances, usually it is faster choice if one of its branches can be NULL:
MEMBER [Measures].[Negative Total Test] AS
IIF(
(
[Measures].[Total]
,[Dim Account].[Account Marketing].&[Income]&[Marketing]
) >= 0
,NULL
,[Measures].[Total] * -1
)
MEMBER [Measures].[Negative Total] AS
IIF(
[Dim Account].[Account Activity].CURRENTMEMBER
IS [Dim Account].[Account Activity].[All]
,SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
,[Measures].[Negative Total Test]
)
According to the screenshot there is no need to include Marketing in the first calc so a further simplification could be:
MEMBER [Measures].[Negative Total Test] AS
IIF(
[Measures].[Total] >= 0
,NULL
,[Measures].[Total] * -1
)
MEMBER [Measures].[Negative Total] AS
IIF(
[Dim Account].[Account Activity].CURRENTMEMBER
IS [Dim Account].[Account Activity].[All]
,SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
,[Measures].[Negative Total Test]
)
WOW ! I got my answers, that's the thing I was looking for. It was nothing but only changes is the display of [Negative Total Test]. I again thanks to Saurav because he gave me life of my MDX code.
WITH
MEMBER [Measures].[Negative Total Test] AS
CASE
WHEN
[Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
[Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
[Measures].[Total]<1
THEN [Measures].[Total]*-1
WHEN
[Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
[Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
[Measures].[Total]>1
THEN NULL
ELSE
[Measures].[Total]
END
MEMBER [Measures].[Negative Total] AS
CASE
WHEN [Dim Account].[Account Activity].CURRENTMEMBER IS [Dim Account].[Account Activity].[All]
THEN
SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
ELSE [Measures].[Negative Total Test]
END
MEMBER [Dim Account].[HierarchyMarketing].[Income] AS
([Dim Account].[HierarchyMarketing].[Account Type].&[Income], [Measures].[Negative Total])
MEMBER [Dim Account].[HierarchyMarketing].[Total Marketing Expense] AS
AGGREGATE
(
{
[Dim Account].[Account Marketing].&[Income]&[Marketing]
,
[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
}
,
[Measures].[Negative Total]
)
SELECT
{
//[Measures].[Total], [Measures].[Negative Total],
[Measures].[Negative Total Test]
} on COLUMNS
,
NON EMPTY
(
{
(
[Dim Account].[HierarchyMarketing].[Account Type].&[Income]
*
{
[Dim Account].[Account Activity].[All]
}
)
,
(
{
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
}
*
[Dim Account].[Account Activity].[Account Activity].MEMBERS
)
,
(
[Dim Account].[HierarchyMarketing].[Total Marketing Expense]
,
[Dim Account].[Account Activity].[All]
)
}
,
// Traders,
[Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire] ,
[Dim Scenario].[Scenario Name].&[Actual] ,
[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
)
on ROWS
FROM [CubeProfitLoss]
;
I should have asked as an another question however I have reached my question limit, sorry for that.
The above question was the part of my problem. The final output should be like my edited picture. According to Sourav's solution, he checked the condition of [Dim Account].[Account Activity].CURRENTMEMBER IS [Dim Account].[Account Activity].[All] that worked perfectly that tiny problem but when I wanted to accumulate with original income (650,920.88) then it's coming up with big figure that's not expected. Another solution I need I want to add up marketing expense(24010.44) with negative marketing income which are already converted (43380.4+9181.32) so finally the result should be 76572.16. Please modify my MDX. Thanks a lot
WITH
//MEMBER [Measures].[Negative Total Test] AS -- (1)
//CASE
// WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) < 0
// THEN [Measures].[Total]*-1
// WHEN ([Measures].[Total],[Dim Account].[Account Marketing].&[Income]&[Marketing]) > 0
// THEN NULL
// ELSE
// [Measures].[Total]
//END
MEMBER [Measures].[Negative Total Test] AS --(2)
CASE
WHEN
[Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
[Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
[Measures].[Total]<1
THEN [Measures].[Total]*-1
WHEN
[Dim Account].[Account Marketing].CurrentMember.MEMBER_CAPTION="Marketing" AND
[Dim Account].[Account Marketing].Properties("Account Type") ="Income" AND
[Measures].[Total]>1
THEN NULL
ELSE
[Measures].[Total]
END
MEMBER [Measures].[Negative Total] AS
CASE
WHEN [Dim Account].[Account Activity].CURRENTMEMBER IS [Dim Account].[Account Activity].[All]
THEN
SUM(
[Dim Account].[Account Activity].[Account Activity].MEMBERS,
[Measures].[Negative Total Test]
)
ELSE [Measures].[Negative Total Test]
END
//MEMBER [Dim Account].[Account Activity].[TOTAL] AS
// [Dim Account].[Account Activity].[All]
MEMBER [Dim Account].[HierarchyMarketing].[Total Marketing Expense] AS
AGGREGATE
(
{
[Dim Account].[Account Marketing].&[Income]&[Marketing]
,
[Dim Account].[Account Marketing].&[Expenses]&[Marketing]
}
,
[Measures].[Negative Total Test]
)
SELECT
{
[Measures].[Total], [Measures].[Negative Total]
} on COLUMNS
,
NON EMPTY
(
{
(
[Dim Account].[HierarchyMarketing].[Account Type].&[Income]
*
{
VisualTotals([Dim Account].[Account Activity].[All])
}
)
,
(
{
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Expenses]&[Marketing]
,
[Dim Account].[HierarchyMarketing].[Account Marketing].&[Income]&[Marketing]
}
*
[Dim Account].[Account Activity].[Account Activity].MEMBERS
)
,
(
[Dim Account].[HierarchyMarketing].[Total Marketing Expense]
,
VISUALTOTALS([Dim Account].[Account Activity].[All])
)
}
,
[Dim Branch].[Trading As].&[BAR]&[Barlens Event Hire] ,
[Dim Scenario].[Scenario Name].&[Actual] ,
[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[December]
)
on ROWS
FROM [CubeProfitLoss]
Related
I am having three columns,- and / should be used as separator result should come in new column(File Index-sub Index/Year),if sub index is blank then result should be (File Index/Year).
SELECT
[ File Index].[File Index]
, [ File Index].[Sub Index]
, [ File Index].[Financial Year]
, [ File Index].[File Index] & [Sub Index] & [Financial Year] AS [Composite Index]
FROM [File Index];
Since you have both MySQL and MS Access listed, here are solutions for both.
For MySQL, you can use a CASE statement for this:
SELECT [File Index], [Sub Index], [Financial Year],
CASE WHEN [Sub Index] IS NOT NULL
THEN Concat([File Index], '-', [Sub Index], '/', [Financial Year])
ELSE Concat([File Index], '/', [Financial Year])
END as [Composite Index]
FROM [File Index];
For MS Access, you will use Switch(...):
SELECT [File Index], [Sub Index], [Financial Year],
Switch(Not IsNull([Sub Index]),
[File Index] & '-' & [Sub Index] & '/' & [Financial Year],
IsNull([Sub Index]),
[File Index] & '/' & [Financial Year]
) as [Composite Index]
FROM [File Index];
You can use IIF function: IIF(Condition;ConcatenationIfTrue;ConcatenationIfFalse)
SELECT
[ File Index].[File Index]
, [ File Index].[Sub Index]
, [ File Index].[Financial Year]
, IIF(ISNULL([Sub Index];[ File Index].[File Index] & "/" & [Financial Year];[ File Index].[File Index] & [Sub Index] & [Financial Year]) AS [Composite Index]
FROM [File Index];
I have calculated my gross profit and wanted to show as a total however, if I run this code it is showing the result of the difference between Income and Cost of Sales with every Account Summary like the following output
that is very awkward My requirement is Income and Cost of Sales have to show the account summary but Gross Profit will have to be only total (one line) instead of explored every account summary. Is there any way/any command to do this in MDX?
WITH
MEMBER [Total] AS
(
[Measures].[Amount]
,[Dim Account].[Account Summary].CurrentMember
)
MEMBER TotalIncome AS
(
[Measures].[Amount]
,[Dim Account].[Account Type].&[Income]
,[Dim Account].[Account Summary].[All]
)
MEMBER TotalCOGS AS
(
[Measures].[Amount]
,[Dim Account].[Account Type].&[Cost of Sales]
,[Dim Account].[Account Summary].[All]
)
MEMBER [Dim Account].[Account Type].[Gross Profit] AS
TotalIncome - TotalCOGS
SELECT
NON EMPTY
[Total] ON COLUMNS
,NON EMPTY
(
{
[Dim Account].[Account Type].&[Income]
,[Dim Account].[Account Type].&[Cost of Sales]
,[Dim Account].[Account Type].[Gross Profit]
,[Dim Account].[Account Type].&[Expenses]
,[Dim Account].[Account Type].&[Other Income]
,[Dim Account].[Account Type].&[Other Expense]
}
,NonEmpty([Dim Account].[Account Summary].[Account Summary])
,NonEmpty([Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[August])
,NonEmpty([Dim Branch].[HierarchyB-T-C].[Branch Code].&[bfy])
) ON ROWS
FROM [CubeProfitLoss];
Maybe your script is very close. Why are you including this member in your calculations? [Dim Account].[Account Summary].[All]
WITH
MEMBER [Dim Account].[Account Type].[Gross Profit] AS
(
[Dim Account].[Account Type].&[Income]
,[Dim Account].[Account Summary].[All]
)
-
(
[Dim Account].[Account Type].&[Cost of Sales]
,[Dim Account].[Account Summary].[All]
)
MEMBER [Dim Account].[Account Type].[Gross Profit V2] AS
(
[Dim Account].[Account Type].&[Income]
)
-
(
[Dim Account].[Account Type].&[Cost of Sales]
)
SELECT
NON EMPTY
[Measures].[Amount] ON 0
,NON EMPTY
{
[Dim Account].[Account Type].&[Income]
,[Dim Account].[Account Type].&[Cost of Sales]
,[Dim Account].[Account Type].[Gross Profit]
,[Dim Account].[Account Type].[Gross Profit V2]
,[Dim Account].[Account Type].&[Expenses]
,[Dim Account].[Account Type].&[Other Income]
,[Dim Account].[Account Type].&[Other Expense]
}
*[Dim Account].[Account Summary].[Account Summary]
*[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[August]
*[Dim Branch].[HierarchyB-T-C].[Branch Code].&[bfy]
ON 1
FROM [CubeProfitLoss];
This is the solution i was looking for. I am really grateful to whytheq - his code helped me to get to this:
WITH
MEMBER [Dim Account].[Account Type].[Gross Profit] AS
([Dim Account].[Account Type].&[Income])
-([Dim Account].[Account Type].&[Cost of Sales])
SELECT
NON EMPTY
[Measures].[Amount] ON 0
,
NON EMPTY
(
{
([Dim Account].[Account Type].&[Income],
[Dim Account].[Account Summary].[Account Summary])
,([Dim Account].[Account Type].&[Cost of Sales],
[Dim Account].[Account Summary].[Account Summary])
,([Dim Account].[Account Type].[Gross Profit],
[Dim Account].[Account Summary].[All])
,([Dim Account].[Account Type].&[Expenses],
[Dim Account].[Account Summary].[Account Summary])
,([Dim Account].[Account Type].&[Other Income],
[Dim Account].[Account Summary].[Account Summary])
,([Dim Account].[Account Type].&[Other Expense],
[Dim Account].[Account Summary].[Account Summary])
}
*[Dim Fiscal Year].[HierarchyFiscal].[E Month].&[2016]&[August]
*[Dim Branch].[HierarchyB-T-C].[Branch Code].&[bfy]
)
ON 1
FROM [CubeProfitLoss];
Imagine today it is the 22nd June 2010 (I've used this date as AdvWrks cube is old)
I would like to find the set of days that make up this month i.e. 1st June - 22nd June plus the days in the previous 5 equivalent months to date.
So these days would make up the set:
(1st Jan 2010 - 22nd Jan 2010) +
(1st Feb 2010 - 22nd Feb 2010) +
(1st Mar 2010 - 22nd Mar 2010) +
(1st Apr 2010 - 22nd Apr 2010) +
(1st May 2010 - 22nd May 2010) +
(1st Jun 2010 - 22nd Jun 2010)
The following gives me this set of 132 days:
WITH
SET [Days in Current Month] AS
[Date].[Calendar].[Date].&[20100601]:[Date].[Calendar].[Date].&[20100622]
SET [Mths in Past 6 Mths] AS
Tail
(
[Date].[Calendar].[Month].MEMBERS
,6
)
SET [Prev Equiv MTDs] AS
Generate
(
[Mths in Past 6 Mths]
,Head
(
Descendants
(
[Mths in Past 6 Mths].CurrentMember
,[Date].[Calendar].[Date]
,SELF
)
,[Days in Current Month].Count
)
)
SELECT
{} ON 0
,[Prev Equiv MTDs] ON 1
FROM [Adventure Works];
Is it possible to find this set of days without using the Generate function?
Here is one way:
WITH SET FirstDateOfMonth AS [Date].[Calendar].[Date].&[20100622].Parent.FirstChild
SET LastDayOfMonth AS [Date].[Calendar].[Date].&[20100622]
SELECT {} ON 0,
//CurrentMonth
{
FirstDateOfMonth.ITEM(0)
:
LastDayOfMonth.ITEM(0)
}
+
//-1 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
1,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
1,
LastDayOfMonth.ITEM(0)
)
}
+
//-2 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
2,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
2,
LastDayOfMonth.ITEM(0)
)
}
+
//-3 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
3,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
3,
LastDayOfMonth.ITEM(0)
)
}
+
//-4 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
4,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
4,
LastDayOfMonth.ITEM(0)
)
}
+
//-5 month
{
ParallelPeriod(
[Date].[Calendar].[Month],
5,
FirstDateOfMonth.ITEM(0)
)
:
ParallelPeriod(
[Date].[Calendar].[Month],
5,
LastDayOfMonth.ITEM(0)
)
}
ON 1
FROM [Adventure Works]
And here is one more:
SELECT
{
[Date].[Calendar].[Date].&[20100622].PARENT.FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(1).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(1)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(2).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(2)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(3).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(3)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(4).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(4)
)
}
+
{
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(5).FirstChild
:
COUSIN
(
[Date].[Calendar].[Date].&[20100622],
[Date].[Calendar].[Date].&[20100622].PARENT.LAG(5)
)
}
ON 1,
{} ON 0
FROM [Adventure Works]
And one more...
WITH SET FirstDateOfMonth AS [Date].[Calendar].[Date].&[20100622].Parent.FirstChild
SET LastDayOfMonth AS [Date].[Calendar].[Date].&[20100622]
MEMBER Measures.PositionOfDate AS {FirstDateOfMonth.ITEM(0):LastDayOfMonth.ITEM(0)}.COUNT
SET Dates AS
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(1).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(2).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(3).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(4).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
+
HEAD(
[Date].[Calendar].[Date].&[20100622].Parent.LAG(5).ITEM(0).CHILDREN,
Measures.PositionOfDate
)
SELECT Dates ON 0,
{} ON 1
FROM [Adventure Works]
And this way too:
WITH SET FirstDateOfSelectedMonth AS [Date].[Calendar].[Date].&[20100622].Parent.FirstChild
SET SelectedDate AS [Date].[Calendar].[Date].&[20100622]
MEMBER Measures.PositionOfDate AS {FirstDateOfSelectedMonth.ITEM(0):SelectedDate.ITEM(0)}.COUNT
SELECT
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(5).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(4).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(3).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(2).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0).PARENT.lag(1).FirstChild.LEAD(Measures.PositionOfDate - 1)
)
+
PeriodsToDate
(
[Date].[Calendar].[Month],
SelectedDate.ITEM(0)
)
ON 1,
{} ON 0
FROM [Adventure Works]
EDIT
Slow code with non-repeating blocks:
WITH SET FirstDateOfSelectedMonth AS [Date].[Calendar].[Date].&[20100601].Parent.FirstChild
SET SelectedDate AS [Date].[Calendar].[Date].&[20100601]
MEMBER Measures.PositionOfDate AS {FirstDateOfSelectedMonth.ITEM(0):SelectedDate.ITEM(0)}.COUNT
MEMBER Measures.PositionOfCurrentDate AS
([Date].[Calendar].currentmember.Parent.FirstChild:[Date].[Calendar].currentmember).COUNT
SELECT
{
[Date].[Calendar].[Date].&[20100601].Parent.LAG(5).FirstChild.ITEM(0)
:
[Date].[Calendar].[Date].&[20100601]
}
HAVING Measures.PositionOfCurrentDate <= Measures.PositionOfDate
ON 1,
{} ON 0
FROM [Adventure Works]
I have the following query that gives me an extract (I am putting this into a CSV from my cube).
I want to show the Total of all NRx in a column as the first column NRx and the rest of the NRx columns should come up as they do now. I tried to add a SUM (Measures.NRx) to this, but it did not work
How do I get a total NRx column?
SELECT
NON EMPTY
CrossJoin
(
[Time Period].[Calendar].[Cycle Dt],
{
[Measures].[NRx]
}
)
ON COLUMNS,
NON EMPTY
{(
[Prescriber].[Prescriber Name].[Prescriber Name].Members
, [Prototype Alignment].[Tier Code].[Lilly Tier Code].Members
, [Prototype Alignment].[Territory Name].[Territory Name].Members
, [Prototype Alignment].[District Name].[District Name].Members
, [Prototype Alignment].[Division Name].[Division Name].Members
, [Prototype Alignment].[Area Name].[Area Name].Members
, [Market Product].[Product Group Nbr].[Product Group Nbr].Members
, [Market Product].[Product G Name Name].[Product G Name Name].Members
)} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM
(
SELECT
({
[Prescriber].[Ims Prescriber Id].&[011111]
}
,
{
[Time Period].[Cycle Dt].&[2008-10-03T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-10T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-17T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-24T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-31T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-07T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-14T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-21T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-28T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-05T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-12T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-12T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-19T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-26T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-26T00:00:00]
}
) ON COLUMNS
FROM [Mart]
) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE,
FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
In the first Crossjoin, where you have
[Time Period].[Calendar].[Cycle Dt],
Try adding a reference to the All member of the Calendar hierarchy
{[Time Period].[Calendar].[Cycle Dt], [Time Period].[Calendar].[All] },
I have the following query that gives me an extract (I am putting this into a CSV from my cube).
I want to show the Total of all NRx in a column as the first column NRx and the rest of the NRx columns should come up as they do now. I tried to add a SUM (Measures.NRx) to this, but it did not work
How do I get a Total NRx column?
SELECT
NON EMPTY
CrossJoin
(
[Time Period].[Calendar].[Cycle Dt],
{
[Measures].[NRx]
}
)
ON COLUMNS,
NON EMPTY
{(
[Prescriber].[Prescriber Name].[Prescriber Name].Members
, [Prototype Alignment].[Tier Code].[Lilly Tier Code].Members
, [Prototype Alignment].[Territory Name].[Territory Name].Members
, [Prototype Alignment].[District Name].[District Name].Members
, [Prototype Alignment].[Division Name].[Division Name].Members
, [Prototype Alignment].[Area Name].[Area Name].Members
, [Market Product].[Product Group Nbr].[Product Group Nbr].Members
, [Market Product].[Product G Name Name].[Product G Name Name].Members
)} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM
(
SELECT
({
[Prescriber].[Ims Prescriber Id].&[011111]
}
,
{
[Time Period].[Cycle Dt].&[2008-10-03T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-10T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-17T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-24T00:00:00],
[Time Period].[Cycle Dt].&[2008-10-31T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-07T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-14T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-21T00:00:00],
[Time Period].[Cycle Dt].&[2008-11-28T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-05T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-12T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-12T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-19T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-26T00:00:00],
[Time Period].[Cycle Dt].&[2008-12-26T00:00:00]
}
) ON COLUMNS
FROM [Mart]
) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE,
FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
What if you made a calculated member before the SELECT query with something like this:
SUM ([Measures].[NRx], [Time Period].[Calendar].[Cycle Dt])?
Then just do:
SELECT
NON EMPTY [MYCALCMEMBER_SUM] * CrossJoin([Time Period].[Calendar].[Cycle Dt], {[Measures].[NRx]}) ON COLUMNS,