SSAS cube - Finding count of days overdue per order - ssas

I'm trying to add a new measure to my OLAP cube, in SSAS.
The fact table is at the order detail level, so each row in the fact table represents an order and a product, like:
I'd like to add a measure that indicates the maximum number of days overdue per order number. So that measure should say:
OrderNo 1 -> 5 days overdue
OrderNo 2 -> 1 day overdue
OrderNo 3 -> 0 days overdue
I have tried using the MAX operator, with no success.
By the way, this is a multidimensional SSAS schema. I'm using SQL Server 2008.
Thanks in advance!

Just define a measure "max days overdue" or how ever you want to call it in the cube designer, tab "cube structure". In the properties of the measure, use "Max" as the aggregate function. That's it.

Related

MDX Calculation Tab

I am new to SSAS and I am trying to write a query in ssas caluculation tab that will show all customers (customername) and items ordered (ItemName) in last 40 days. I am not sure is calculation tab the best option to do this.
I have got only one measure VOLUME and dimension attributes (customername,itemname,officename,shipdate ...) I have got also Date Hierarchy with Year->Q->Month->Date.
I have got this statement that gives me netvolume for specific itemname in last 40 days, but what i am looking for is all customers and items ordered in last 40 days. I do not need measure. ( this 40 days might change to 20 or 60 days)
SELECT
{ [Measures].[NET VOLUME]} ON COLUMNS,
FILTER
(
{[CUBENAME].[SHIPDATE].&[2018-03-23T00:00:00]:[CUBENAME].[SHIPDATE].&[2018-05-01T00:00:00]},
[CUBENAME].[ITEMNAME].&[11# RPC 6411]
) ON ROWS
FROM[CUBENAME]
Try using named query in the DSV and filter based on the date field.

Issues excluding data in SSAS cube (different output in SSMS and SSAS using EOMONTH())

I'm creating a cube whose stock values should only conclude the last day each month's balance and value.
Hence, I've created the following Query in SSMS:
Create table #theStockTable(
Stock int,
StockValue INT,
DateKey int
)
INSERT INTO #theStockTable
VALUES(3,5, 20170211),
(3,5,20170228),
(1,4,20170331),
(1,4,20170330)
SELECT CAST(CONVERT(varchar, DateKey, 112) AS numeric(8, 0)) AS DateKey, SUM(Stock) AS [CL Stock], SUM(StockValue) AS [CL Stock Value]
FROM #theStockTable
WHERE CONVERT(date, CONVERT(varchar(10), DateKey)) = eomonth(CONVERT(date, CONVERT(varchar(10), DateKey)))
GROUP BY DateKey
In SSMS this returns the correct values:
DateKey CL Stock CL Stock Value
20170228 3 5
20170331 1 4
However, when I create an OLAP cube using SSAS, and use the Query above as the Named Query for my fact table #theStockTable and the same Query as my only partition of the same fact table and deploy and execute the cube, I have a situation where I get different values on each day of every month, but I only want to have the values for each month's last day.
I have used New Project.. -> Import from Server (multidimensional model or data mining model) in SSAS. It is important that the users must be able to browse the cube as they presently do.
The cube whose meta data I have copied contains every day's values on the stock table. May there be some metadata change I need to make in addition to the Query modification I have done in Edit named Query.. in Data Source View and replacing the old Query in the partition with my new Query?
Hopefully someone can shed some light into this.
EDIT
To clarify my request, some users of the cube has explained that it is rather slow to browse in for instance Excel, mainly because my Stock measure is much bigger than it is required to be. As it is now, it returns every StockValue and Stock of each product and each day. I want to only include the total balance of StockValue and Stock of the last day of the month. All other stock values are redundant.
For instance, browsing my DimDate dimension table with the measurements Stock and StockValue should have this return set:
DateKey Stock StockValue
20170131 0 0
rather than the whole return set which is returned now:
DateKey Stock StockValue
20170101 3 5
20170102 4 6
20170103 1 1
20170131 0 0
I think you already had a date dimension in your cube, if yes, then follow these steps:
Add an additional attribute [IsLastDay] with value 0/1 in the date dimension to indicate if the current date record is the last day of that month or not.
2.Add a calculate measure [CalStock] with this formular:
([Measures].[StockValue],[Date].[IsLastDay].&[1])
3.Fire this query to return the expected result:
select {[CalStock]} on 0,
non empty{[Date].[Date].[Date]} on 1
from [YourCube]

Create MDX to Divide two measures for each month and then sum the all of the months

I have a multidimensional cube that needs a custom measure that I'm not sure how to build.
That data looks like this:
MemberID-----Date-------EventType
1--------------1/1/2016-------1
2--------------1/1/2016-------2
3--------------2/1/2016-------1
2--------------2/1/2016-------2
4--------------2/1/2016-------2
There is a count measure in the cube, but others can be added if needed. I need to create a measure that will use whatever filters the user applies and then count the EventType (1 and 2 only) by month, divide the resulting counts for EventType 1 into the count for EventType 2 (for each month individually), and finally sum the monthly results. For example 1/1/2016 would be 1/1=1 (count of EventType 1 and count of EventType 2) and 2/1/2016 would be 1/2=0.5 so the resulting measure value for the two months would be 1+0.5=1.5. Any help is greatly appreciated.
Let's assume you have a Date dimension with an attribute called Month. And let's assume you have an EventType dimension. And let's assume you have a count measure in your measure group called Cnt. Here's what else you need to do.
First, go to the DSV and add a new calculated column to the fact table which is called NullInt and is the following expression:
cast(null as int)
Then create a new Sum measure in your measure group off that column and call the measure My Rollup. Under the Source property, change NullHandling to Preserve so that it will start off null.
To explain why we're doing this, a scoped assignment to a physical measure will aggregate up. (If you assign a value to a physical measure at the grain of each month, then it will rollup to the grand total.) But a scoped assignment to a calculated measure doesn't roll up.
Then in your MDX script add the following calculations:
scope([Date].[Month].[Month].Members); //calculate at the month level then rollup
[Measures].[My Rollup] = DIVIDE(
([Event Type].[Event Type].&[1],[Measures].[Cnt]),
([Event Type].[Event Type].&[2],[Measures].[Cnt])
);
end scope;
Note that your version of SSAS probably has the DIVIDE function if it's AS2012 with the latest service pack or newer. But if it doesn't, you can always do division the old fashioned way as IIF(denom=0,null,num/denom).

MDX expressions to aggregate data at certain level for calculated member

For now sometimes I have problems with creating difficult calculated members in SSAS. Is it possible to make case which will SUM certain measure on certain level when user choose another certain level of dimension? For example we have standard time dimension with 4 levels:
Year
Month
Week
Day
Also we have some measure orders which have default function SUM in properties.
Which case do we need to calculate this: sum all orders in week which including current day which we have chosen already.
Also could you recommend me some nook or source for level up my mdx knowledge?
Thanks a lot.
Yes, it's possible, when you use MDX functions, which are connected with levels.
Here is an example with Year > Quarter > Month > Day hierarchy:
Use MDX calculated member to have a SUM of upper level member children (including selected one):
The same if you want to create calculation inside the cube:
CREATE MEMBER CURRENTCUBE.[Measures].[SameLevelMembers]
as SUM({[Report Date].[Report Date].CurrentMember.Parent.Children},[Measures].[Count]),
VISIBLE = 1 ;
And a result in cube browser:
Hundreds of articles you can find there: http://ssas-wiki.com/w/Articles#MDX
I also like this one: http://mdxpert.com because of well-structured info.

MDX - sum costs up to a given date

This is a slight modification of what I stumbled upon while searching the web:
Let's say I have a dimension PROJECTS which contains:
project_id - unique id
category - category of a cost
project_date - date of summing up the cost
My warehouse also has the dimension of TIME with date, and a dimension COSTS containing values of costs. Those three dimensions are connected by the measure group EXPENSES which has:
id_date
id_cost
id_project
I want to wirte an MDX query which would group the projects by their category, and sum up all the costs, but only those which do not exceed the date given in the project_date attribute of the dimension PROJECTS (each category has the same project_date, I know it's redundant but I can't change it..)
I'm not sure, but maybe something alongside this?
SELECT
[COSTS].[COST] ON 0,
[PROJECTS].[category] ON 1
FROM [CUBE]
WHERE
[PROJECTS].[project_date] < #project_date