Showing data in a Pivot Table as a % - excel

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

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 can I split weekly data to monthly using Excel/ Power Pivot?

My Data is in weekly buckets. I want to split the number into a monthly number but, since there is an overlap in days falling in both the months, I want a weighted average of the data in terms of days that fall in each of the months. For example:
Now, in the above picture, I want to split that 200 (5/7*200 in Jan, 2/7 in Feb). How can I do that using Excel/ Power Pivot/ Dax Functions? Any help here is much appreciated.
Thank you!
Assuming your fact table looks something like below. Values are associated with the starting date of the week it occurred.
Although it may actually be a more granular data, having multiple rows for each week with additional attributes (such as identifiers of a person, a store, depending on the business), what being shown below will work the same.
What we need to do first is to create a date table. We can do that in "Design" tab, by clicking "Date Table", then "New".
In this date table, we need to add a column for starting date of the week which the date of each row is in. Set the cursor to "Add Column" area, and input following formula. Then rename this column to "Week Start Date".
= [Date] - [Day Of Week Number] + 1
Now, we can define the measure to calculate the number allocated to each month with following formula. What this measure is doing is:
Iterating over each row of the fact table
Count the number of days for the week visible in the filter context
Add the value portion for the visible days
Value Allocation := SUMX (
MyData,
VAR WeekStartDate = MyData[Week]
VAR NumDaysInSelection = COUNTROWS (
FILTER (
'Calendar',
'Calendar'[Week Start Date] = WeekStartDate
)
)
VAR AllocationRate = DIVIDE ( NumDaysInSelection, 7 )
RETURN AllocationRate * MyData[Value]
)
Result in the pivot table will be looking like this.

Previous Year row in measurement, DAX formula

I have the following table:
Year test is the list of previous year:
=SUMX(Datasrc;Datasrc[Year]-1)
How do I get something similar for "Calculated field 1"? In other words, I want to get the previous "Price/kg" so it match column C, "Year test".
I have tried with the formula from Find rows relative to current row's value in excel (DAX):
=SUMX(
FILTER(Datasrc; EARLIER([Year]) = [Year] + 1 );
Datasrc[C_Total Asset Per Share]
)
But only get: "Calculation error in measure 'Datasrc'[Calculated field 2]: EARLIER/EARLIEST refers to an earlier row context which doesn't exist."
The column A is [Year]
DAX has time intelligence functions built in, so it's fairly easy to do what you'd like using the SAMEPERIODLASTYEAR function.
First you need a date table joined to your fact table. Then just do
CALCULATE ( [Base Measure], SAMEPERIODLASTYEAR(DateTable[Date]) )

Cumulative return in a PivotTable?

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.

Excel pivot table calculated field total returns unexpected value

I have an Excel spreadsheet which has a pivot table on it. The data itself is quite simple, Number of Units and a Discount (percentage from 0 to 100), pivoted on date across the top and customer down the left hand side. Those numbers are straight from a SQL view, so the pivot table source is just:
SELECT * FROM UnitDiscountView
All was looking fine until I attempted to add a calculated field of TotalCost (Each unit will costs £200) to the pivot table:
= (200 *NrUnits ) * ((100-Discount)/100)
The total at the bottom was negative, and vastly more than I was expecting as a number. If I select all the cells, then the sum which appear in the status bar at the bottom is what I would expect, but the Total field at the bottom is over a hundred times bigger, and negative to boot.
I am stumped. I have searched since Friday without finding anything which will help me to solve this. Any pointers on where to start looking for the solution would be greatly appreciated. I should mention that SQL is my forte, not Excel. I haven't used Excel's Pivot tables before last week, so I am probably missing something really obvious.
Calculated fields will work with the totals:
200 * (Sum of NrUnits) * ((100 - [Sum of Discount]) / 100 )
So for your total row, if Sum of Discount is greater than 100 (adding up all the Sums of Discount on the pivot table), the part of your formula (100-Sum of Discount) will be returning a negative number, hence the negative value.
What I normally do is to add another column to the table to the right of the values returned from the query. I will add my formulas there, then do the pivot table on the resized table.
If you have formatted the returned SQL query as a table (or list in Excel 2003), the pivot table source range should even resize by itself.
I found the answer.
Excel was effectively doing this for the total:
= (200 * sum(NrUnits)) * ((100-sum(Discount))/100)
Which isn't even close to what I wanted:
= sum((200-NrUnits) * ((100-Discount) * 100)))
I got round it by changing the SQL from the view to be:
SELECT *, NrUnits*((100-Discount)*100) AS EffectiveUnits
FROM UnitDiscountView
And the Calculated field to:
= EffectiveUnits * 200

Resources