I'm trying to build a cube which will contain a history of product prices by on-line sellers. So, it has one simple "fact" table and three dimension tables. The fact looks like this:
product_id
seller_id,
price_date,
product_price
and the dimensions are product, seller, and date. The product dimensions rolls up into manufacturers (so products can be grouped by manufacturers). The seller dimensions just has the seller name, and the date dimension has the normal complement of date levels.
I'd like to have the cube respond to users by not displaying any data unless the user has drilled down into the sku level, and the individual seller level, although I wouldn't mind having the aggregations be averages on the manufacturer level.
But for the date dimension I would like the cube to display lastnonempty.
When I choose lastnonempty as the aggregation property, the prices get summed along the manufacturer and seller dimensions, which is wrong.
Here is a sample of what I'd like to see:
fact table:
date product manufacturer seller price
1/1/2000 sku1 manu1 seller1 $10.00
1/2/2000 sku1 manu1 seller1 $12.00
cube result
manu1 -
sku1 -
Jan 2000 $12.00
1/1/2000 $10.00
1/2/2000 $12.00
Is this possible?
Thanks, --sw
Be careful actually nulling out subtotals since this makes it very difficult for users to even start a PivotTable. I blogged about this dilemma and a solution here:
http://www.artisconsulting.com/blogs/greggalloway/2012/6/8/na-for-subtotals
So it is possible. Try something like:
scope( [Product].[Product].[All], [Measures].[Price] );
this = IIf(IsEmpty([Measures].[Price]),null,0);
Format_String(this) = ";;"; //format zeros as blank
end scope;
Then repeat that code to blank out the manufacturer and seller subtotals.
You can switch the AggregateFunction on your Price measure to LastNonEmpty. But I tend to prefer LastChild for the reasons mentioned here and here. It does add a little more MDX to use LastChild as I explained in that second article. And you may be ok with LastNonEmpty if every product is snapshotted every day.
Related
I am working on a simple project using SSAS Cube on SQL Server 2016 and SSDT2015. DW_Orders database is from Orders DW. The table factor orders contains attributes UnitPrice, Quantity and Discount with the calculation member TotalSale defined as [Measures].[Unit Price][Measures].[Quantity](1-[Measures].[Discount]), well as the FK members CustomerID and OrgID. I want to get the TotalSale based on Country-City Hierarchy from dimension dimCustomers. But I got the following result:
enter image description here
it is obvious that the UnitPrice, Quantity and Discount have been summed under the city or country so that we got wrong and negative result of TotalSale from the calculation. Tried in the Edit Measure, cannot get what I expect. Need your help on some settings, thanks.
You need to edit the aggregation type for the 2 measures(discount and unit price). By default, the type is SUM, you need to use Average. To do that, go to the measure group, select the measure and access its properties to set the aggregation.
I am a graduate intern at a big company and I'm having some trouble with creating a measure in PowerPivot.
I'm quite new with PowerPivot and I need some help. I am the first person to use PowerPivot in this office so I can't ask for help here.
I have a fact table that has basically all journal entries. See next table. All entries are done with a unique ID (serialnumber) for every product
ID DATE ACCOUNT# AMOUNT
110 2010-1-1 900 $1000
There is a dimension table with has all accounts allocated to a specific country and expense or revenue.
ACCOUNT# Expense Country
900 Revenue Germany
And another dimension table to split the dates.
The third dimension table contains product information, but also contains a column with a certain expense (Expense X).
ID Expense X ProductName Productcolour
110 $50 Flower Green
I made sure I made the correct relations between the tables of course. And slicing works in general.
To calculate the margin I need to deduct this expense x from the revenue. I already made a measure that shows total Revenue, that one was easy.
Now I need a measure to show the total for Expense X, related to productID. So I can slice in a pivot table on date and product name etc.
The problem is that I can't use RELATED function because the serial number is used multiple times in the fact table (journal entries can have the same serial number)
And if I use the SUM or CALCULATE function it won't slice properly.
So how can I calculate the total for expense X so it will slice properly?
Check the function RELATEDTABLE.
If you create a dummy dataset I can play around and send you a solution.
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
I am encountering an issue in which I have sales which can be part of multiple promotions. I am trying to use a sales fact table which will have multiple rows for sales in multiple promotions. Thus, the cube can only accurately be used to aggregate sales within a promotion, not across promotions.
e.g., here are a couple of rows that could appear in the fact table:
saleid sku sales_date promotion_id revenue
1 123 1-1-2013 1 10
1 123 1-1-2013 2 10
This is one sale which gave the company revenue of $10, but it was part of two different promotions. I want to give users the ability to sum sales for promotion 1, and sales for promotion 2, but not for all promotions at the same time (which would indicate $20 of sales overall).
I think that this should be able to be done in SSAS, but I can't figure out how to do it. Ideally the cube would be defined so that the user can only use it in conjunction with the promotion dimension (and other dimensions as desired), but I'd settle for defining the facts so that they cannot be summed across promotions.
thanks, --sw
I have a problem and was wondering if anyone could help or if it is even possible to have an algorithm for something like this.
I need to create a predictive ordering wizard. So based on previous sales, we will determine that that a certain amount of an item is required. E.g 31 apples. Now i need to work out the number of cases that needs to be ordered. If the cases come in say 60, 30, 15, 10 apples, the order should be a case of 30 and a case of 10 apples.
The number of items that need to be ordered change in each row of the result set. The case sizes could also change for each item. So some items may have an option of 5 different cases and some items may land up with an option of only one case.
Other examples would be i need 39 cans of coke and the cases come in only 24 per case. Therefore needing 2 cases. I need 2 shots of baileys and the bottle of baileys come in 50cl or 70cl. Therefore i need the 50cl.
The results sets columns are ItemName, ItemSize, QuantityRequired, PackSize and PackSizeMultiple.
The ItemName is the item to be ordered. ItemSize is the size the item is used in eg. can of coke. QuantityRequired how man of the item, in this case cans of coke, need to be ordered. PackSize is the size of the case. PackSizeMultiple is the number to multiply the item with to work out how many of the items are in the case.
ps. this will be a query in SQL Server 2008
Sounds like you need a UOM (Unit of Measure) table and a function to calc co-pack measure count and and unit count measure qty. with UOM type based on time between orders. You would also need to create a cron cycle and freeze table managed by week/time interval in order to create a freeze view of the current qty sold each week and the number of units since last order. Based on the 2 previous orders to your prior order you would set the current prediction based on min time between the last 2 freeze cycles containing an order and the duration of days between them. based on the average time between orders and the unit qty in each order, you can create a unit decay ratio percentage based on days and store it in each slice forward. Based on a reference to this data you will be able to create a prediction that will allow you to trigger a notice to sales or a message to the client to reorder. In addition, if you engage response data from sales based on unit count feedback from the client, you can reference an actual and tune your decay rate against your prediction. You should also consider managing and rolling up these freezes by month, so that you can view historical trending and forecast revenue based on velocity of reorder and same period last year. Basically this is similar to sales forcasting and we are switching out your opportunity percentage of close with Predicted Remaining Qty. percentage remaining.