MDX calculation should not work on subtotals in excel - excel

My granule record-set is like this:
I use the calculation below to avoid duplicate sum, [Measures].[TRANSACTION TOTAL AMOUNT] / [Measures].[TRANSACTION ALL COUNT] so, for TranId=1; 450 / 3 = 150
it works on every single TranId fine and I want to see: 150+80+70 = 300
excel pivot subtotal. But it shows: 910 / 19 = 47.89. I don't want it to calculate my mdx calculation for totals or subtotals! I just want dummy summarize

To answer your question as written, turning off the subtotal can be done with this added statement in your MDX script:
[Your Dimension Name].[TranID].[All] = null;
However I think you are modeling your data incorrectly. You just need to add a new measure group which has one row per TranID and create a Sum measure to get proper details and totals.

Related

DAX to find percent of total based on filter (regardless of view)

How do I create DAX that finds the percent of incidents that are Status=Closed based on row view
Total Incidents = Count of CREATED_DATE
I tried following Measure both gave error
`% Closed:=if(Table1[STATUS]="Closed",[Count of CREATED_DATE],0)/[Count of CREATED_DATE]`
and
% Closed2:=DIVIDE(if(Table1[STATUS]="Closed",[Count of CREATED_DATE],0),[Count of CREATED_DATE],0)
Sample data from Power Pivot.
Here is my table
Here is what I wish to create. Please note, the % of Closed Incidents to Total should change based on how I filter the power-pivot, i.e. if I filter to include ONLY closed incidents, then naturally the % should be 100%
What you need is the Calculate function, which allows for calculations under different contexts. Think of it as excel's sumif function but a bit more powerful.
So for example the below, which would do a count of the BBL rows where the table1 status is closed. Note for count the column has to be a number or date.
Closed Count:=CALCULATE( COUNT( Table1[BBL]), Table1[STATUS] = "Closed")
Then you can do your divide. Keep in mind that not putting the alternative result, means that in a divide by zero error power pivot will return NULL. The advantage being that if a all measures in a row evaluates to null it will be suppressed in the pivot.
Total Incidents:=COUNT( Table1[BBL])
Closed %:=DIVIDE( [Closed Count], [Total Incidents])

SpotFire - How to get cumulative percentage

I need to obtain Cuml % in Spotfire; how to do? Please refer the below data-set
Data Set
You'll want to use the OVER function. I re-created your data table, then inserted three calculated columns:
ActualCuml = Sum([Actual]) OVER (AllPrevious([Day]))
PlannedCuml = Sum([Planned]) OVER (AllPrevious([Day]))
CumlPct = [ActualCuml] / [PlannedCuml]
The first two calculated columns are your rolling sums for Actual and Planned, and then the third column just divides those two new columns to get the cumulative percentage.
You could just insert a single calculated column and use the expressions from the first two as the division factors:
Sum([Actual]) OVER (AllPrevious([Day])) / Sum([Planned]) OVER (AllPrevious([Day]))

Sum up values on distinct rows filter

I need to calculate the total shipping cost for some sales orders. The dataset is as follows:
The issue I have is that although the shipping cost should be taken into account only once per order in the calculation, in the dataset it is repeated for each order item, thus a simple duplicates shipping costs:
=SUM(MyTable[Shipping]) = 90 // wrong value
However what I need is to:
filter the table to only keep 1 line for each order
sum up the shipping
Which should be something like:
=SUMX(FILTER(MyTable,<filter>),MyTable[Shipping]) = 35 // correct value
But I'm struggling to write the <filter>. I found DISTINCT which returns the list of unique order IDs, but not their corresponding row.
Does anybody have any ideas how I could write the filter to calculate shipping properly?
The X functions are non intuitive but very powerful - you are on the right lines.
I would approach this with two measures, the first to sum the shipping cost and divide it by the number of rows for that order. (Key to the second half is the ALL() which opens up the context on the column referenced whilst retaining the other contexts.)
And the second to iterate that measure by order and sum the outcomes.
[Allocated Shipping] =
SUM ( MyTable[Shipping] )
/ CALCULATE ( COUNTROWS ( MyTable ), ALL ( MyTable[Item] ) )
[Iterated Shipping] =
SUMX(VALUES(MyTable[Order]), [Allocated Shipping])
The simplest approach would be to use a Helper column. In E2 enter:
=IF(COUNTIF($A$1:A2,A2)>1,0,1)
and copy down. This will identify the unique values in column A. To sum these unique values, use:
=SUMPRODUCT(--(E2:E9=1)*(D2:D9))
For your data:
The value is 35
Naturally if the data were filtered you would use a variation of the SUBTOTAL() function or an additional helper column.
In a very similar way to Gary's recommendation, you could use (in an additional col - E2):
=IF(COUNTIF($A$2:A2,A2)>1,D2,0)
This will show the cost of the delivery in col E itself. You can then just SUM(E2:E) to see the total cost (35).

Is there a function like AVERAGEX but counts instead of averaging the sums?

I have a function in PowerPivot Excel that gives me the average of the summed rows, and only counts if the sums are 100%.
The reason I do this: For each order coming in on one trailer (load), some of the items were not completely fulfilled, therefore "Is On Time" is set to 0 instead of 1 for each. I then average the whole load to see the total "on time" percentage.
Formula:
On Time:=AVERAGEX(VALUES('table1'[Loads]), IF(AVERAGE[Is On Time]=1, 1, 0))
Here's an example of what the table in PowerPivot looks like, and what I'd like the output to eventually look like:
Is there a way to do the same but only count the total instead of averaging it all. I was hoping COUNTX but it doesn't work the same.
Something like :
{ = MIN( IF( $A$3:$A$11=D3, $B3:B$8 ) ) }
Or
=IF(COUNTIFS($A$3:$A$11;"="&D3;$B$3:$B$11;"=0")>0;1;0)
This KPI seems to work. (Is On Time is a KPI to give me the average of the column, which is usually 1s or 0s)
Loads OT:=COUNTX(VALUES('table1'[Load]), IF([Is On Time]=1, 1, BLANK()))
The only issue I have is it returns BLANK if no rows were counted. Is there a way to make it return a 0?

PivotTable - Calculate value depending on combination of row labels

WARNING - Using Excel 2011 for Macs, inexperienced user
Hi All,
I have a sheet in Excel with a bunch of categorical fields and some numerical ones as well. Let's say it looks like the following:
I would like to make a pivot table that will display the average click rate (avg_click_rate) of the unique combinations of [year, region], i.e. the combinations of fields in the pivottable's rows section.
For example, the avg_click_rate of [years=5] is:
(0.5*10)/(10 +5 ) + (0.6*5)/(10+5) = 0.53
while the avg_click_rate of [region=north] is:
(0.6*5)/(5+20) + (0.2*20)/(5+20) = 0.28
and the avg_click_rate of [years=5, region=south] is:
(0.5*10)/10 = 0.5
I know I have to make a custom Calculated Field to do this, but for the life of me I cannot figure out how to code the formula. Any help would be seriously, seriously appreciated.
To be clear, my formula would be:
SUM{ (click_rate * number_members) / SUM{number_members} }
where the numerator is a single value for each row included in the unique combination of [year, region], while the denominator is a constant - the total number_members for the unique combination of [year, region].
You should create a new column in your source table:
product = click_rate * number_members
And then create a Calculated Field in the pivot table:
CF = product / number_members
Using AVERAGEIFS:
AVERAGEIFS($C$2:$C$9,$A$2:$A$9,A2,$B$2:$B$9,B2)
EDIT:
You can add up to 127 conditions, see: AVERAGEIFS function
Criteria_range1, criteria_range2, … are 1 to 127 ranges in which
to evaluate the associated criteria.

Resources