MDX - Applying a month summary value to a dimension - mdx

I am trying to apply a measure value calculated at the Month level to a dimension contained within that month i.e.
Should look like this:
I've attempted to use a scoping statement so far but with no luck.
SCOPE (
{[Sale].[Sale Year].&[2]:[Sale].[Sale Year].&[7]}
,[Date].[Calendar Month].&[201603]
,[Measures].[Costs Per Sale] );
THIS = ([Date].[Calendar Month].&[201603],[Measures].[Costs Per Sale]);
END SCOPE;
The Aggregated Sales measure is calculated using the Sale Year which unfortunately has not and cannot be linked to the Cost dimension.
Does anyone know how I can apply the Cost Per Sale monthly value to the [Sale].[Sale Year] dimension?
Thanks

Try this -
SCOPE ({[Sale].[Sale Year].&[2]:[Sale].[Sale Year].&[7]} ,[Measures].[Costs Per Sale]);
THIS = ([Sale].[Sale Year].[All],[Measures].[Costs Per Sale]);
END SCOPE;

Related

AVG(EXISTING()) syntax error

I want to calculate sales for promotion using it's date. I need 3 measures, avg sales from 21 days before promotion start date, sales in between of promotion's start and end date, and sales from 21 days after promotion's end date.
Why Visual Studio highlights avg in code below?
CREATE MEMBER CURRENTCUBE.[Measures].[Sales in promotion]
AS Avg(Existing([Promotion].[Promotion name].[Promotion name]),[Measures].[Sales]), ...
Same in here:
CREATE MEMBER CURRENTCUBE.[Measures].[Sales before promotion]
AS (EXISTING([Promotion].[Promotion name].[Promotion name]), AVG(strtomember("[Date].[Date].&["+ [Promotion].[Date].currentmember.member_key+"]").lag(21) : strtomember("[Date].[Date].&["+ [Promotion].[Date From].currentmember.member_key+"]"),
[Measures].[Sales])) ...
If I do sum(existing()) in first measure, the sum is calculated correctly, but it doesn't allow me to get average.
EXISTING will only help if [Promotion] is part of your query in either the WHERE or SELECT clause. If it is not included in either of these clause then EXISTING will be finding 1 member - the All member.
You could try NonEmpty and maybe move the period logic into a custom set?
WITH
SET [PERIOD] AS
STRTOSET(
"[Date].[Date].&["+ [Promotion].[Date].currentmember.member_key+"].lag(21)
:
[Date].[Date].&["+ [Promotion].[Date From].currentmember.member_key+"]"
)
From the code you posted I cannot tell if you want a daily average or and average per promotion ? Say there were 2 promotions over the 21 days does this mean you want (Total/2/21) ?

How to calculate Actual Sales per day using DAX

I'm trying to get Actual Sales per day using DAX howver I can't able to get the Actual Sales Per Day using DAX Expression.
I'm using below DAX to calculate Total No. of days.
b:=CALCULATE(COUNT(DimDate[Date]),DimDate[CY_Year]=YEAR(TODAY()),USERELATIONSHIP(Fact_Sales[Doc_Date],DimDate[Date]))
Please provide the correct formula.
Assuming [a] is a measure in the Data Model then you just create a new measure for Actual Sales Per Day as follows:
c :=
[a] / [b]
If [a] is not already a measure in the Data Model then create it first as follows:
a :=
SUM ( [SalesAmount] )

Calculated member to get dimension value in previous year

I am new to BI and need help to create a calculated member.
I have a cube with following dimension and measure:
Dimension tables:
Dim_Time (Year, Month, Day)
Dim_MyValueCollection: DataType with data types having values 'Gross Paid Claims' and 'Gross Written Premiums'
Measure:
FactTable.Value
I need to create a calculated member on Dim_MyValueCollection.DataType to represent the difference of 'Gross Written Premiums' values in current and previous year.
To get data from a previous period in mdx you can use these functions:
Lag
https://msdn.microsoft.com/en-us/library/ms144866.aspx
ParallelPeriod
https://msdn.microsoft.com/en-us/library/ms145500.aspx
Have you attempted any mdx ?
Edit
Here is a general tuple for the change in Gross Written Premiums since the same period in the previous year. I've guessed the names of your dimensions because you have not supplied any sample mdx:
([Time].CURRENTMEMBER, [Measures].[Gross Written Premiums])
-
(PARALLELPERIOD(Year,1,[Time].CURRENTMEMBER), [Measures].[Gross Written Premiums])

How to filter time hierarchy based on anothr attribute's value in MDX

I want to create a calculated member. I have a time dimension hierarchy" YQM", which has Year/Quarter/Month. The calculated member should find YTD till the current month. However, the value of current month will come from database.
I have created a attribute, "CP" which returns the current month value.
Please tell me how to create the calculated member. Please note "CP" is not in the same hierarchy YQM.
I don't understand why you are using Aggregate. So, I will assume that it is there for some purpose, which you have't clarified. Now, if the members of [YQM].[Month] and [Dim].[CP] are of the same format, then you can try the code below:
Aggregate(
PeriodsToDate([Dim].[YQM].[Month].MEMBERS,
FILTER([Dim].[YQM].[Month].MEMBERS,
[YQM].[Month].CURRENTMEMBER.member_value = [Dim].[CP].FirstChild.member_value)
)
)
Why not try playing with the function YTD. The following should give you the monthly amount in the first column of data and then the YTD amount in the next column:
WITH MEMBER [Measures].[YearToDate] AS
AGGREGATE(
YTD()
,[Measures].[someMeasureInCube]
)
SELECT
{
[Measures].[someMeasureInCube],
[Measures].[YearToDate]
} ON 0,
[Dim].[YQM].[Month].MEMBERS ON 1
FROM [yourCube]

Count maximum sequel of null values - mdx query

I want to create a member based on this problem
I have a Product A being sold
I want to find the largest range of consecutive days without sale
example:
days 1,2,3 the product not sale, after that,it sold for 15 consecutive days, at 19th day it didnt sell for 2 days and after that it sold every day until the end of the month
so my maximum days without sale was 3
The following query delivers in the Microsoft sample cube Adventure Works what you want:
WITH Member Measures.[days without sales] AS
IIf( [Measures].[Internet Sales Amount] > 0
, 0
,(Measures.[days without sales], [Date].[Calendar].CurrentMember.PrevMember) + 1
)
Member Measures.[Max days without sales] AS
Max( [Date].[Calendar].[Date].Members
,Measures.[days without sales]
)
SELECT { [Measures].[Max days without sales] }
ON COLUMNS
FROM [Adventure Works]
WHERE [Product].[Product].&[486]
The measure days without sales is defined recursively, and returns how many days up to and including the current member of the [Date].[Calendar] hierarchy there was no sales. You may need to adapt the criteria for "without sale", bearing in mind that in MDX, numerical comparisons treat NULL as 0 - which is different from SQL.
This measure only works correctly if there is a member in this hierarchy for each day, i. e. there are no gaps in this hierarchy. And actually, the definition is more general than just working for days: If you use months for the [Date].[Calendar].CurrentMember, it would give you the number of months without sales, etc. It works with each level of the hierarchy.
The measure Max days without sales does not contain the product in its definition, it delivers the maximum days for whatever is in context (in this case the product in the WHERE clause).
Please note that - as actually there is a loop over all days in the [Date].[Calendar] hierarchy when calculating Measures.[Max days without sales], and within that the recursion again iterates along the previous days, and all this for each cell in the result set - this may be slow for large reports.