Can Pivot Table perform operations comparing two field? - excel

I have a table that has two category columns, a column for number started and a column for number finished. I'd like to roll up by one category column and calculate a percentage finished in a pivot table (rather than array formulae).
Imagine my data looks like this:
Date - School - Starters - Finishers
7/1 USC 100 25
7/1 UCLA 200 50
7/2 USC 250 100
7/2 UCLA 200 100
I want my pivot table to look like this
Date - Finish rate
7/1 25%
7/2 44%
But when I go into Value Field Settings to switch to a calculation, I can't figure how to get the column comparison to happen.

You can create a calculated field that compares two other fields in the "Pivottable Tools" "Analyze" ribbon "Fields, Items, & Sets" button - "Calculated Field". Just build comparison expression in the "Formula" text field of the "Insert Calculated Field" dialogue box.

Related

Excel Pivot - Calculate average for values > XX

Data table simplified - read only:
<table border=1>
<tr><th>Date</th><th>Hours</th></tr>
<tr><td>Jan. 1</td><td>6.5</td></tr>
<tr><td>Jan. 2</td><td>8.5</td></tr>
<tr><td>Jan. 3</td><td>7.5</td></tr>
<tr><td>Jan. 4</td><td>9.0</td></tr>
</table>
Now I would like a pivot table that can calculate the average number of hours - only taking into account the days where the number of hours are > 8.0. Ie. for the above data the pivot should return 8.75.
I've tried with calculated field: =If(Hours > 8, Hours, NULL) - or blanks instead of null or similar.
Please help.
You don't need a Pivot table. Just use =AverageIf([Range of Hours],">8")
Edit:
To achieve through Pivot Table, I can only think of using "measure". But it could be quite slow for 120k rows as the Filter() function need to go through each row one by one.
create a the Pivot Table with the checkbox "Add this data to the Data Model" clicked;
Right-click on the "Range" (or the table name if your data is a table) in the Field List and choose "Add Measure"
Enter the measure's info and use =SUMX(Range, if(Range[Hour]>8, Range[Hour],0))/ COUNTROWS(FILTER(ALL(Range), Range[Hour]>8)) as formula (replace "Range" with Table name if source data is a table). And click "OK".
Then, you can use this measure to get the average value you want.

How to use Or filters for getting data from OLAP cube pivot table in Excel

We are loading data from an SSAS model (cube) into an Excel pivot table. The data within the spreadsheet needs to be shown using 2 conditions in OR way, I mean, I have 2 fields coming from the database: Original amount and amendment amount, We need display the information coming from the SSAS cube when original amount <=10.000 OR amendment_amount<=10.000.
I tried to use the normal filters on Excel pivot tables, but it doesn't worked, because filters use AND implicitly to display information, I need OR.
I tried to use the normal filters on Excel pivot tables (value and label filters), but it doesn't worked, because filters use AND implicitly to display information, I need OR.
example:
Code original amount amendment amount
C1 25000 500
C2 2000 18000
C3 14000 9000
C4 12000 10500
Filtering by Original_amount<=10.000 and amendment_amount<=10.000 is noy displaying any records
The result expected is C1,C2 and C3 code records displayed because one og the both conditions is true...
How could I filter for displaying the right data?
Using the example described above, the result expected is C1,C2 and C3 code records displayed because one of both conditions is true...
results expected:
Code original amount amendment amount
C1 25.000 500
C2 2.000 18.000
C3 14.000 9.000
How could I filter for displaying the right data?
Create a calculated measure in the PivotTable which is called Show Row:
IIF(
(
Not(IsEmpty([Measures].[original amount]))
AND [Measures].[original amount] <=10000
)
OR
(
Not(IsEmpty([Measures].[amendment amount]))
AND [Measures].[amendment amount]<=10000
),
1,
Null
)
Then add that calculated measure to your PivotTable and filter to keep only rows where Show Row >= 1.

Calculate median of aggregated values for a category using pivot table

I have hourly data about sales $ of certain categories (Fruits, snacks etc). I'd like to display the median of daily sales values over a month or an year using the hourly data in the table. So, for each category it needs to sum the hourly values and create a daily value first and then calculate the median
regular pivot does not provide median function. I am familiar with Power pivots but have not used Measures. i tried to create a measure using medianX function, but could not make it work
First, you will need to add a Calendar table to your data model:
Calendar Table Explained
The Calendar table must have fields you want to group your sales by, such as "Year-Month" and "Year-Quarter".
Then, connect the Calendar table to your Sales table via date fields, to get a structure like this:
With this data model in place, create 2 measures ( I will assume your sales table is called "Sales", and calendar table is called "Date"):
Measure 1:
Total Sale = SUM(Sales[Amount])
It will simply calculate sum of sale amounts.
Measure 2:
Median Monthly Sale = MEDIANX( VALUES(Date[Year-Month]), [Total Sale])
This measure will first sum up sales by Year-Month, and then calculate the median of the sums.
To get median sales by a different period, just replace Year-Month with the desired grouping level, for example:
Median Yearly Sale = MEDIANX( VALUES(Date[Year]), [Total Sale])
Ali,
When you create your measure you will want to use the MEDIAN funciton not MEDIANX
The MedianX would be if you were trying to calculate the median value for a column in your table that did not already exist.
For Example, lets say we have Table1 which has two columns Net Revenue and Net Expense. And the following 3 data points exist for each row in the column.
Net Revenue:
Jan-2019 100
Feb-2019 300
Mar-2019 300
Net Expense:
Jan-2019 50
Feb-2019 100
Mar-2019 50
Since we do not have a Net Profit column in the table we could use MEDIANX to specify the table we would like to use then write our expression for the column that doensn't exist. In the example above it would go =MEDIANX(Table1, [Net Revenue] - [Net Expense]. This would create a median measure for NetProfit even though the column itself doesn't exist in our table.
In your case, since you are aggregating a column that already exists you can just stick with =MEDIAN.
If you need more clarification let me know!
Best,
Brett

Pivot table with multiple items per transaction

I am trying to create a pivot table and pivot chart in excel 2016 based off of cattle auction data. Data for each auction includes: Head of Cattle, total weight, avg weight, price per lb, and price a head. I am trying to show the avg price per head of particular weights. The trouble is when one transaction is for 30 head # $800 and the next is for 1 # $700 it shows average price of $750. But I want to show the average weight of the 31 cattle at $796 not the average of the transactions # $750. Any ideas?
From what you've laid out in your question, it sounds like you should do some calculations in your data before you pivot it. Basically, make a new column that is [transaction] * [the head of cattle], so in this case the new column values are 24000 and 700, respectively.
From there, you can insert a pivot table and use a custom calculation. While in the pivot table click on 'Options' and then click on "Fields, Items, & Sets". Then set the calculation in the formula bar to your new field divided by head of cattle.

Pragmatically Get Count of Pivot Table Data

Suppose I have some sample data like so:
and I create a Pivot Table and order by Product > Sales Rep > Sales
If I want the # of sales John had for Product1 I would do =GETPIVOTDATA("Sales",$A$3,"Product","Product1","Sales Rep","John")
But how would I get a count of the entries there are. i.e. for Product1, John had 4 and Kevin had 2
Is it possible to get this count using GETPIVOTDATA()?
To get this you need to add another Sales field to the values section and change the "Summarize By" to Count. Then the formula will =GETPIVOTDATA("Count of Sales",$A$3,"Product","Product1") will get you the count of Product Overall.

Resources