MDX new measure based on two derived measures - ssas

I have two calculated MDX measures based on units and discount. I need to calculate sum of units for each discount value.
I need to perform this calculation only in MDX (2008). Similar to sum over( partition by discount) in SQL.
Example
Product Disc Units SumofUnits
Mango 5% 10 15
Apple 5% 5 15
Apple 7% 8 18
Apple 7% 10 18
Any help is greatly appreciated.

Could you please provide more details about your cube structure? Do you have the Discount attribution? If so, you have to run the following:
SUM(
[Discount].[Discount].[Discount].Members,
[Measures].[Disc]
)

Related

SSAS MDX Script View New Calcuated Measure against a different date

I'm a real newbie to MDX.
I'm trying to learn/get my head around how to create a new measure taking an existing measure and put against next date e.g.
Sales:
20190101 Qty 100
20190102 Qty 40
new measure to show
20190102 Qty 100
20190103 Qty 40
I've tried this:
create member currentcube.[Measures].[Qty Previous]
as
([Dim Date].[Date ID].currentmember.prevmember,[Measures].[Qty]);
Which does work but only when Date Dimension is used.
The existing Sales measure will work with any dimension (Time, Product, Location), how can I do this?
If you are not explicitly using a Date member your existing measures will be aggregating at the All level.
you can fix that in your usage dimension in VS

sum top 80% and count on how many customers make it up

I'm trying to build a sales query for a rolling 12 months. I know my sales by customer, and my total sales. I'm trying to sum up the top 80% of sales $ and give a count on how many customers make up that 80%. Any ideas? I have a result set that looks like the below. Thanks in advance!
Customer Sales TotalSales PercentOfSales
8585 19788.81 769658.68 0.03
8429 19598.26 769658.68 0.03
2837 19431.29 769658.68 0.03
6071 19398.11 769658.68 0.03
5027 19223.13 769658.68 0.02
6677 19204.90 769658.68 0.02
I actually have similar issue, only difference is i'm using Hive. i'm not sure if you've tag your question properly, think it's more than a sql-server-2008 issue.
my solution is:
query (use sql) all the records in order of desc.
loop all the records (use any other program languages) to accumulate the value of sales, and put the current customer into a list (say "VIPList")
loop stops when accumulated value is >= the 80% of total value
then all the customer in the VIPList that are what you wanted.

SSAS cube - Finding count of days overdue per order

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.

How to model and define a fact that can have multiple values for a dimension in an ssas cube

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

identifying trends and classifying using sql

i have a table xyz, with three columns rcvr_id,mth_id and tpv. rcvr_id is an id given to a customer, mth_id is a column which stores the month number( mth_id is calculated as (2012-1900) * 12 + 1,2,3.. ( depending on the month). So for example Dec 2011 will have month_id of 1344, Jan 2012 1345 etc. Tpv is a variable which shows the customers transaction amount.
Example table
rcvr_id mth_id tpv
1 1344 23
2 1344 27
3 1344 54
1 1345 98
3 1345 102
.
.
.
so on
P.S if a customer does not have a transaction in a given month, his row for that month wont exist.
Now, the question. Based on transactions for the months 1327 to 1350, i need to classify a customer as steady or sporadic.
Here is a description.
The above image is for 1 customer. i have millions of customers.
How do i go about it? I have no clue how to identify trends in sql .. or rather how to do it the best way possible.
ALSO i am working on teradata.
Ok i have found out how to get standard deviation. Now the important question is : How do i set a standard deviation limit on my own? i just cant randomly say "if standard dev is above 40% he is sporadic else steady". I thought of calculating average of standard deviation for all customers and if it is above that then he is sporadic else steady. But i feel there could be a better logic
I would suggest the STDDEV_POP function - a higher value indicates a greater variation in values.
select
rcvr_id, STDDEV_POP(tpv)
from yourtable
group by rcvr_id
STDDEV_POP is the function for Standard Deviation
If this doesn't differentiate enough, you may need to look at regression functions and variance.