Total And GrandTotal CUBE different - mdx

I Have CUBE table that support the pivot table like this
why the grand total diifrent with the TOTAL?
is there something wrong with MDX?

Related

Grouping ORDER ITEMS from hourly to daily

I would like to SUM the price of these Order Items together for each Order for a Contract.
I want to reduce my granularity from hourly to daily and so reduce the row count that we pass to the fact table and then the SSAS cube.
i.e. Contract A which can have many Orderlines, consider Orderline 1 which can have many Order Items.
I have had to screen the Order Items, but they are just sequential id numbers.
The problem is that I have to roll this up to a daily granularity from hourly, but still be able to give users on the cube access to the Order Item level
you can use SUM as a window function. this will effectively write the same sum to multiple rows for each order-item; just like the price.
for example
SELECT ......
, SUM(price) OVER (PARTITION BY order_item)
....
FROM ....
GROUP BY ....

forcing SSAS respecting relationships between dimensions

with regard to the following question and the given response I have the following question:
I am facing the same issue, but creating a bridge table like mentioned above is no option in my case as I still need the separate dimensions for other operations and different analysis.
For budgeting reasons I have to show all customers even if they have no match with the fact table. Enabling the corresponding option in EXCEL obiously leads to a cross join of the selected dimensions resulting in a complete list of all customers in all countries, although not each customer exists in all countries.
Is there another altrnative to force SSAS respecting relationships defined?
Many thanks in advance for assistance.
Let’s say you have FactSales with CustomerKey, CountryKey, DateKey and SalesAmount. When you build a PivotTable in Excel with Customer and Country on rows and SalesAmount on columns it only shows customers with sales. If you set Excel to show rows with no data it shows all customers in all countries.
Try building a new FactCustomerCountry table with CustomerKey and CountryKey only. Create a measure Customer Country Count.
Then create a new calculated measure:
CREATE MEMBER CURRENTCUBE.[Measures].[Sales Amount with Zeros]
AS
IIF(
IsEmpty([Measures].[Customer Country Count]),
Null,
CoalesceEmpty([Measures].[SalesAmount], 0)
);
Use that measure in your PivotTable instead of SalesAmount. Do not show rows with no data. The measure should return meaningful Customer-Country combinations and should return all customers.
Hi you can solve your issue in MDX. Take a look at the query below, its an example on Adventureworks. This will fetch all the products that were sold and the quaters that they were sold in.Now some products were never sold, I still want to see those product.
select [Measures].[Internet Sales Amount] on columns,
--non empty
{filter(([Product].[Subcategory].[Subcategory],[Date].[Calendar Quarter of Year].[Calendar Quarter of Year]),[Measures].[Internet Sales Amount]>0),
filter(([Product].[Subcategory].[Subcategory],[Date].[Calendar Quarter of Year].defaultmember),[Measures].[Internet Sales Amount]=null)
}
on rows
from
[Adventure Works]

SSAS best way to count Orders by number of Products ordered

I'm looking for the best way to implement measure that counts Orders by the number of products ordered.
There is a fact table of ProductsOrdered, like this
CREATE TABLE ProductsOrdered (
IdOrder UNIQUEIDENTIFIER,
IdProduct UNIQUEIDENTIFIER,
OrderDate DATE,
Quantity INT,
Price DECIMAL(18,2)
)
for every order there are rows in the table for every kind of product ordered.
I would like to have a measure that counts how many ordered a single product, how many 2, and so on.
Just like this SQL query does.
SELECT OrderedProductNumber, COUNT(IdOrder) AS NumberOfOrders
FROM (
SELECT IdOrder, COUNT(IdProduct) AS OrderedProductNumber
FROM ProductsOrdered
GROUP BY IdOrder
) t
GROUP BY OrderedProductNumber
Which MDX expression is best counterpart?
Thanks.
The problem you have is that you can only produce a count by a dimension. In this case, your dimension is the products ordered (1, 2, 3, etc.) Your option is to create a physical dimension that has the range of possibilities (tedious), or to create "dummy" members for a dimension to do the same thing as a calculation (tedious AND likely a performance problem). I would lean towards creating a dimension for products ordered, and then create a fact table using your SQL query and add the dimension and measure group to the cube. It's going to be easier to implement in the long run and by physically instantiating the counts, you will get much better query performance.
You can define dimension based on product
then measure group based on fact table, that you named ProductOrdered,
then you can define distinct count measure based on your IOrder column (e.g [IOrderdistinctcount])
after that you can use
select
{IOrderdstinccount} on 0,
[dim Product].[product].[Product].members on 1
from [Cube]

MDX equivalent to SQL's GROUP BY for excluding duplicate rows

My cube has a fact table that contains a row for every modification made to any entity. What I need is a measure that will return a count of the entities based on the selected dimensions.
So if the user selects a month from the date dimension then the measure should return the number of entities that were modified that month (rather than the number of modifications).
In SQL this would be something like:
SELECT EntityID, COUNT(*)
FROM FactTable
WHERE Date BETWEEN X AND Y
GROUP BY EntityID
How can you do this in MDX? Surely this would be an extremely common scenario with cubes.
Your t-sql query is equivalent of mdx query:
select
[Measures].[<Fact rows count measure>] on columns,
<Entity dimension members> on rows
from [<Cube Name>]
where (<month member>)
In the above query [Fact rows count measure] would be a measure with aggregation formula Count - count of rows
However, if you need to return the distinct count of entity members when you slice by another dimension, you basically have several options:
create a distinct count measure on the entityID key
create a calculated measure with expression: count(exists(existing [Entity].[Entity].[Entity].MEMBERS,,'Measure Group Name'))
HTH,
Hrvoje Piasevoli

SQL query (in ZOHO reports) to join two tables by subtotas :-O

if you are out there, please help me:
I have 2 different tables, with different columns and no primary key:
1 - daily actual sales data
2 - monthly budget sales data
I need:
- one consolidated table with monthly actual sales (counted) and montly budget sales, to compare monthly sales vs budget.
Is it possible?
Of course.
You can aggregate the numbers for every month from the actual sales data table using sum() and group by and can join into this the budget table via the month column.