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.
Related
I have 2 large tables in power pivot and I am trying to reconcile stockpile build grades to crushed stockpile grades. Please see example. I can create pivot table that contains the crushed grades but I am unable to find the right way to bring the stockpile grades though for the reconciliation high lighted in green in the attached example.
Thanks for any help or direction on where to look
In Power Query, create your lookup tables.
1) unique crushers, ID
2) Dates, ID
Here is a function to create a dates table, if you need one. After you invoke the function to get the column of dates, add another column for the ID.
/*--------------------------------------------------------------------------------------------------------------------
PQ Create a Dates Table, returning a single column of dates.
Inputs:
Start Date | Enter the year as yyyy, month as mm, day as dd
End Date | Enter the year as yyyy, month as mm, day as dd
Increments | One row will be returned per increment.
Author: Jenn Ratten
Edits:
07/16/18 | Modified query copied from the internet.
10/01/19 | Converted to a function.
--------------------------------------------------------------------------------------------------------------------*/
let
fDatesTable = (StartYear as number, StartMonth as number, StartDay as number, EndYear as number, EndMonth as number, EndDay as number, IncrementDays as number, IncrementHours as number, IncrementMin as number, IncrementSec as number) as table =>
let
StartDate = #date(StartYear,StartMonth,StartDay),
EndDate = #date(EndYear,EndMonth,EndDay),
Increments = #duration(IncrementDays,IncrementHours,IncrementMin,IncrementSec),
DatesTable = Table.FromColumns({List.Dates(StartDate, Number.From(EndDate) - Number.From(StartDate), Increments)}, type table[Date]),
ChangeType = Table.TransformColumnTypes(DatesTable,{{"Date", type date}})
in
ChangeType
in
fDatesTable
Load all of the tables to the data model.
Go to Power Pivot, diagram view, and create your relationships.
Lookup Crusher to data tables 1 and 2
Lookup Date to data tables 1 and 2
Go to Data View on data tables 1 and 2, add 2 new columns for the lookup IDs. You can specify the column header and the formula at one time by clicking in first cell and using this syntax, then either press enter or click the check mark in the formula bar.
Dates Lookup ID:=RELATED(lookup_dates[ID])
Crusher Lookup ID:=RELATED(lookup_crusher[ID])
Optional, but a good practice....
Right-click the new fields you just created and select "hide from client tools". Also hide the date and crusher fields on both data tables, and the ID field on both lookup tables. When you are creating pivots to summarize data from more than one table, the text fields that you place on your pivot table should be the fields that are shared (aka the lookup tables). This helps to minimize pivots in which the grand totals don't match the sum that you actually see on the table. If you hide the fields, it reminds you of that. There are exceptions of course, but this is a good rule of thumb.
Now create measures to sum the tons and any other math calculations you'd like. With the measures, start simple and let the pivot do the slicing. Put the measures in the values section of the pivot table.
Sum of Source Tons:=sum(Table1[Tons])
Sum of Destination Tons:=sum(Table2[Tons])
This is the sample of raw data. It shows the value that each of the property got on a scale of 1-10.
Pivot Table showing count of Value on scale for each property
I want to create a custom column in a pivot table in excel or a matrix in power Bi. This column should be based on the columns in the pivot table and not on the already existing columns in the table.
Eg. I have a table with column labels from 1 to 10 and a Total column. I created a pivot table to show the count of each of these columns. In the example here, Mountain has 162 values of 8, 197 values of 9 and 268 values of 10. My question is I want to create a new custom column which is the sum of just these three values divided by the total count. In this example , it is(162+197+268)/829 = 76%
I am not able to do it. Please help me out
In Power BI you're looking at measures something like this.
SurveyCount := CountRows(MyTable)
CountAllValues := CALCULATE(SurveyCount,ALL(MyTable[Value On A Scale (1-10)]))
Count8Plus := CALCULATE(SurveyCount,MyTable[Value On A Scale (1-10)] >= 8)
Percentage8Plus := DIVIDE(Count8Plus , CountAllValues )
The syntax might need a little tweak but these four should get you close to what you need.
I'm getting frustrated trying to get the each cell to show itself as a % of the "Total days" in that row, e.g. where it says 51.8 for "Billed Days" on the first row I'd like it to say 85.6% (51.8 / 60.5 * 100= 85.6%).
Pivot Table
Every time I try to use the "Show total as % of row" option it doesn't work. Same goes with choosing "Show total as % of parent row". Both of these options either return 100% or, their % of the whole territory.
Is what I'm asking possible? As Total Days is a calculation of the pivot table itself, does that mean you can't do calculations in the pivot table based upon it?
Try creating a new calculated field in the Pivot Table, and in the formula type in:
= 'Billed Days'/sum('Total Days')
If that doesn't work, try
= sum('Billed Days')/sum('Total Days')
I'm assuming that when you say "Total Days is a calculation of the pivot table itself", it is simply a calculated field with a formula of: sum('Total Days')
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.
I have a table of daily data in Excel. Let's say it's daily stock return data that looks like:
Date, DailyReturn
1/1/2001, .021
1/2/2001, .005
1/3/2001, .0034
1/4/2001, .013
....
12/31/2001, .004
The data is in a table on one of the sheets. Let's call it TableOfData. I've added a pivot table on another sheet, and I've added the date as the Row Labels. I've also added grouping by year and month to the rows. Now it is easy to add the average and stddev of the returns for each month, but I would also like the total return for the month, which would be calculated as Product(DailyReturn + 1) -1
I can add a calculated field called DailyReturnFactor, which is simply DailyReturn + 1, and I can add the Product of that field to the values and the pivot table shows the return for each month, except that I still need to subtract 1. That is where I'm stuck. Any ideas on if this is possible? The other issue is that I would like to do other sets of calculations as well, e.g. kurtosis.
Note I'm using Excel 2007.