PivotTable - Calculate value depending on combination of row labels - excel

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.

Related

MDX calculation should not work on subtotals in 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.

How do i convert sumifs in excel to a PowerBI formula?

I am trying to replicate the following excel formula in PowerBi. It adds all the refunded costs from a Unique identifier between a date period
I have tried using the Sumx function in powerBi but It doesn't return the values i need it to return.
SUMIFS([#Refunded;
[#Date];">="&MAX([#Date])-42;
[#Date];"<="&MAX([#Date])-14;
[#UID];)
It needs to return the sum of the same unique identifiers between 42 and 14 days earlier.
I have tried solving is as follows:
calculate(SUM([Refunded]),DATESBETWEEN(all_funnel_data_view[Date].[Date],Value(all_funnel_data_view[Date].[Date])=TODAY()-42,Value(all_funnel_data_view[Date].[Date])=TODAY()-14))
But is only returns empty field
Use the FILTER function as the second argument of CALCULATE. In this, you can filter the date column of the all_funnel_data_view table for a date in the specified time frame. I'm assuming that Refunded is a column, not already a measure. If so, qualifying it with the name of the table will help to make the measure easier to read. In the following example, "YourFactTable" is used for this.
CALCULATE
(
SUM(YourFactTable[Refunded]),
FILTER(all_funnel_data_view,
AND
(
all_funnel_data_view[date] >= TODAY() - 42,
all_funnel_data_view[date] <= TODAY() - 14
)
)
)

Using tbl.Lookup to match just part of a column value

This question relates to the Schematiq add-in for Microsoft Excel.
Using =tbl.Lookup(table, columnsToSearch, valuesToFind, resultColumn, [defaultValue]) the values in the valuesToFind column have a consistent 3 characters to the left and then varying characters after (e.g. 908-123456 or 908-321654 - i.e. 908 is always consistent)
How can I tell the function to lookup the value based on the first 3 characters only? The expected answer should be the sum of the results of the above, i.e. 500 + 300 = 800
tbl.Lookup() works by looking for an exact match - this helps ensure it's fast but in this case it means you need an extra step to calculate a column of lookup values, something like this:
A2: =tbl.CalculateColumn(A1, "code", "x => LEFT(x, 3)", "startOfCode")
This will give you a new column that you can use for the columnsToSearch argument, however tbl.Lookup() also looks for just one match - it doesn't know how to combine values together if there is more than one matching row in the table, so I think you also need one more step to group your table by the first 3 chars of the code, like this:
A3: =tbl.Group(A2, "startOfCode", "amount")
Because tbl.Group() adds values together by default, this will give you a table with a row for each distinct value of startOfCode and the subtotal of amount for each of those values. Finally, you can do the lookup exactly as you requested, which for your input table will return 800:
A4: =tbl.Lookup(A3, "startOfCode", "908", "amount")

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]))

Minimum & Maximum - having two compulsory conditions

I have 3 columns with the following name:
name1, name2 and value.
I want to obtain in another sheet two tables having two compulsory condition (min and max calculated using name1 and name2):
the name of the first table to be taken from the column with name2 and this table has two partition.
the first partition named max, is calculating the max for 30_-20, 40_-20, 50_-20, 30_22, 40_22, 50_22, 30_60, 40_60, 50_60 and second partition named min, is calculating the min for 30_-20, 40_-20, 50_-20, 30_22, 40_22, 50_22, 30_60, 40_60, 50_60.
What I want to say can be viewed in the following picture.
I need this for my job, and I don't know anything about macros. I think it will be necessary to learn macros.
Given a layout on a single worksheet similar to your sample image.
    
The standard formula(s) for G3, I3, M3 and O3 are:
=MAX(INDEX($C$2:$C$999*($A$2:$A$999=H3)*($B$2:$B$999=H$1), , ))
=MIN(INDEX($C$2:$C$999+(($A$2:$A$999<>H3)+($B$2:$B$999<>H$1))*1E+99, , ))
=MAX(INDEX($C$2:$C$999*($A$2:$A$999=N3)*($B$2:$B$999=N$1), , ))
=MIN(INDEX($C$2:$C$999+(($A$2:$A$999<>N3)+($B$2:$B$999<>N$1))*1E+99, , ))
Fill down as necessary. It is usually easier to reference a cell containing a value (e.g. 30_-20) than repeatedly hardcoding the value into a variety of similar formulas. I've used H3:H5 and N3:N5 for the column A values.
How it Works:
See MINIF, MAXIF and MODEIF with Standard Formulas.

Resources