How to create cache for the query where the measure has a condition, is there any other better way to do it?
Every time the results comes back in 6 seconds, I want to make it less than 2 seconds
WITH MEMBER TotalPaidHigh AS SUM
(
Filter (
{
[Employee].[EmployeeID].Members},
[Measures].[Score] <= 4 AND
[Measures].[Score] >= 1
}
),
[Measures].[PaidAmount]
)
MEMBER TotalPaidLow AS
(
([Measures].[PaidAmount]) - (TotalPaidHigh)
)
SELECT
{
TotalPaidHigh, TotalPaidLow
} ON 0
FROM
[Cube]
WHERE
(
{
[Date].[Month].&[April 2011],
[Date].[Month].&[May 2011],
[Date].[Month].&[June 2011]
}
,[Geography].[State].&[NY]
)
The best approach would be to define PaidHigh as an additional physical measure in the cube. Then the pre-aggregated values of that measure would be cached by Analysis Services, and it would only have to do the final calculation on the results of teh aggregations - which is fast.
Related
SELECT NON EMPTY {
[Measures].[Production_Volume]
} ON COLUMNS,
NON EMPTY { (
[Make].[Make ID].[Make ID].ALLMEMBERS
* [Model].[Model Hierarchy].[MDL].ALLMEMBERS
* [Customer].[Customer ID].[Customer ID].ALLMEMBERS
) } ON ROWS
FROM [Model_Cube]
This query is taking 10 min
[Measures].[Production_Volume] is a calculated member in the cube, if I put the definition of this member directly in the query it's taking much lesser time.
WITH MEMBER [Measures].[Production_Volume] AS
([Measures].[Model Count],
([Status].[Status Type].&[T]
,[Mode].[Mode Type].&[A])
)
+ Sum(
([HYBRID_MODELS]
,[Status].[Status Type].&[C]
,[Mode].[Mode Type].&[A])
,[Measures].[Model Count]
)
SELECT NON EMPTY {
[Measures].[Production_Volume]
} ON COLUMNS,
NON EMPTY { (
[Make].[Make ID].[Make ID].ALLMEMBERS
* [Model].[Model Hierarchy].[MDL].ALLMEMBERS
* [Customer].[Customer ID].[Customer ID].ALLMEMBERS
) } ON ROWS
FROM [Model_Cube]
this query is taking 4 sec
Unable to understand the difference between the two, I ran the profiler but couldn't find any difference, except that the first query showed flight recorder snapshot events second query didn't.
The problem was how I created named sets "[HYBRID_MODELS]". I changed them from DYNAMIC to STATIC this helped. Another change I did was replace -{} with the EXCEPT() function. These both changes reduced query time from 30min to 1min!
Hope this helps someone in need :)
I have a fact table containing columns OriginalPrice and PaidPrice for customer transactions. I would like to know how many transactions befenit from a discount OriginalPrice - PaidPrice between 10 and 20 dollars. I already have a measure #Customer that describes the number of customers.
This is for a PowerBI report using a Live connection to SSAS. New columns and some DAX functions are not available in this connection mode.
DiscountTier1 = CALCULATE([#Customer],(FactTable[OriginalPrice]-FactTable[PaidPrice]) >= 10, FactTable[OriginalPrice]-FactTable[PaidPrice]) < 20)
By doing this I want to know the number of customers that had a discount between 10 and 20 dollars.
Currently I have an error as follows:
CALCULATE has been used in a True/False expression that is used as a table filter expression. This is not allowed
Any suggestions of how to achieve this or what I am doing wrong?
Thank you!
Add the FILTER function as the second parameter of CALCULATE, and in this you can filter the fact table for records satisfying your criteria. I'd also recommend using the AND function for better readability and long term maintenance.
DiscountTier1 =
CALCULATE (
[#Customer],
FILTER (
FactTable,
AND (
FactTable[OriginalPrice] - FactTable[PaidPrice]
>= 10,
FactTable[OriginalPrice] - FactTable[PaidPrice]
<= 20
)
)
)
You are searching for a measure like this:
DiscountTier1 =
COUNTROWS(
FILTER(
SUMMARIZE (
'FactTable';
'FactTable'[customer_id];
"DISCOUNT";
CALCULATE(SUM(FactTable[OriginalPrice])) - CALCULATE(SUM(FactTable[PaidPrice]))
);
[DISCOUNT] <= 20 && [DISCOUNT] >= 10
)
)
This query calculates the discount of all rows, and filter the rows with a discount between 10 and 20
I have two dimensions, lets say Date Hierarchy and Product and a measure which has MAX (Measures.[Max]) aggregation.
The requirement would be to have SUM of Measures.[Max] on DAY or HOUR level of Date Hierarchy and be summarized in Month level.
I have the following query:
With
Member Measures.SumOfMax as SUM([Date].[Hierarchy].[Hour].AllMembers, Measures.[Max])
Select
NON Empty
{
Measures.SumOfMax
} ON COLUMNS,
NON EMPTY
{
[Date].[Hierarchy].[Month].AllMembers *
[Product].[Product Name].[Product Name].Allmembers
} Having Measures.[Max] > 0
ON ROWS
FROM [Cube]
Above query runs very slow. Are there any ways to optimized this?
The problem with this query is that the calculated measure Measures.SumOfMax is evaluated for every cell on the axis although it's yielding the same value each time. SSAS engine is not intelligent enough to understand that, but since you know about this behavior, you can take advantage of FE caching so that it gets evaluated only once and gets cached in FE cache. Read more on it here
With
Member Measures.[_SumOfMax] as SUM([Date].[Hierarchy].[Hour].AllMembers, Measures.[Max])
Member Measures.[SumOfMax] as ([Date].[Hierarchy].[Hour].[All], Measures.[_SumOfMax])
Select
NON Empty
{
Measures.SumOfMax
} ON COLUMNS,
NON EMPTY
{
[Date].[Hierarchy].[Month].AllMembers *
[Product].[Product Name].[Product Name].Allmembers
} Having Measures.[Max] > 0
ON ROWS
FROM [Cube]
Hope this helps.
If I create a set of tuples via the following crossjoin which hierarchy is joined to which first?
hierA * hierB * hierC
If I know that the count of non empty members in A and B are significantly less than the count of members in C then should this influence the order?
It depends on the execution system used, i.e. how crossjoining on axis is optimized by compiler.
Anyway, you will get real boost only if you first reduce cube size with subselect - it will prevent crossjoining non-matching points:
select
{ [Measures].[X] } on 0,
{ [DimA].[A] * [DimB].[B] } on 1
From (
select { [DimB].[B].members} on 0
from CubeA
)
I have created a cube with many different aggregations and any summing I do is within MDX. I am modeling lottery behavior based on previous drawings. Here is my current code:
WITH
SET [Alpha And Beta And Theta] AS
NONEMPTY (
{ [Dwtbl Dim Test Alpha].[Alpha PK].MEMBERS } *
{ [Dwtbl Dim Beta].[Beta PK].MEMBERS } *
{ [Dwtbl Dim Theta].[Theta PK].MEMBERS }
)
MEMBER Measures.TotalHits AS
SUM ( [Alpha And Beta And Theta]
, COALESCEEMPTY([Measures].[Hits],0)
)
MEMBER [Measures].[PrevMonth_TotalHits] AS
(ParallelPeriod ([Date].[CalendarYear].[Month NK]
, 1
, [Date].[CalendarYear].Currentmember
)
,[Measures].[TotalHits]
)
SELECT
{
[Measures].[TotalHits],
[Measures].[PrevMonth_TotalHits]
} ON COLUMNS
FROM [cubAgents]
WHERE ( [Date].[Year].[2013],
[Date].[Month NK].[7])
Now, when I pass in July, the code works as expected; I get hit counts from July and June. However, when I pass in August [8] which has not occurred yet, I get null for both current and previous month.
Why does this happen? Well, my set [Alpha And Beta And Theta] is a big nonempty crossjoin, with each dimension not occurring since it is in the future. If I remove the nonempty, it will work just fine ... but take 3 minutes to complete. I have spent too much time on this and I guess it is time to reach out to the experts.
Perhaps one method would be to directly sum my [Hits] measures for a previous month as opposed to using parallelPeriod, something like
MEMBER [Measures].[PrevMonth_Hits] AS
SUM ( {[Alpha And Beta And Theta]*[Date].[CalendarYear].Currentmember.LAG(1)}
, COALESCEEMPTY([Measures].[Hits],0)
)
This doesn't work.
Any help is greatly appreciated. Thanks!