I have a PivotTable in Excel, and I'm trying to add a custom field with a custom calcuation, but it doesn't seem to work. As of right now, the PivotTable looks like this...
Part Count of Ordered Sum of Ordered myCustomField
ABC 4 3500 3500
The formula for myCustomField looks like this:
= SUM(Ordered) / COUNT(Ordered)
The value for myCustomField should read 875, but it's not. What am I doing wrong or not understanding about this? Also, even though this custom calculation could be added in a column outside of the PivotTable and work, I need it part of the table which is why I'm adding it through a custom field. Thank you.
Instead of using a calculated field like this, put another Value in your pivot table and make it the Average of Ordered.
Related
I had created a Pivot which uses Power Bi model as it's data source (Analysis services). Since my data is huge and there limitations of pivot, I am exploring other ways of pulling the data.
I converted the sample Pivot to Olap Formula and I think this is the best solution from all the options I have explored. But there is some odd situation I am facing where I need some help.
I tweaked the structure as shown below. So now whenever I change any string like in the below example if I manually change the currency from SGD to USD, I am getting the result. But whenever I try to Manually change any numeric value like Segment, I am getting #N/A. The same numbers when pulled using pivot gives the number.
I have tried to insert the numeric value in following ways
40
'40
="40"
=text("40",0)
text to columns->text
but till now I am not able to crack this.
The cubevalue function expects dimensions on which it is going to filter the values. If you want to provide the value manually you'll have to do it like this:
=CUBEVALUE("Sales","[Measures].[Profit]","[Time].[2004]","[All Product].[Beverages]")
Meaning you'll have to change the 40 to something like [MyDimension].[MyHierarchy].[40]
I'm not able to take the means for a large dataset given that the amount of attributes is irregular.
I have posted a simplified case for the problem. It explains the problem very well.
An idea that I came up with: Make a filter to condition on a single attribute. However, still, I don't see a way to do this in an efficient way (other then doing it all by hand).
see excel file:
All help is much appreciated.
I'm basically looking for a function/method to achieve taking means of all different attributes conditioned on each person for a large dataset without doing it by hand.
You can use AVERAGEIFS() inside an IF:
=IF(OR(A2<>A1,B2<>B1),AVERAGEIFS(C:C,A:A,A2,B:B,B2),"")
the ifrst part of the if tests whether the row starts a new group either by the person or the attribute changing. Then it uses AVERAGEIFS() to return the correct average of that group. otherwise it returns a blank
What you want to do can be accomplished very simply with a pivot table.
Simply select one of the cells inside the range of data you want to process(See the video for general use of a pivot table https://www.youtube.com/watch?v=iCiayB6GrpQ )
go the insert tab and insert pivot table.
Once you have it, simply check people, attribute, and values. Then drag people and attribute into rows, drag valut into the values window, select the drop down list and change it from sum of value to average and you should be done. https://i.stack.imgur.com/nYEzw.png
I just ran into a pivot table VBA issue I've never noticed before. When a pivot table has more than one data field then referring to a PivotItem.DataRange returns a range that is shifted one row down from where it should be. Below you can see the address is off one row and that the selection is below the pivot table - again off by one row:
If the pivot table has only one data field, e.g., if I get rid of "Sum of Total" above, the issue goes away.
I found one reference to this by Macro Marc here on SO, but nothing else on the web. Does anybody have any knowledge of this, e.g., how consistent it is, the best way to code around it, etc.? I can think of a few ways to check for this, but yuck!
Possible Solution:
In my very limited testing it seems like there isn't a similar issue for PivotFields. So my best idea is to compare the first row of a pivot field against the first row of its first pivot item. However, I'm not sure that my concept of "first" will always be the same as Excel's. Anyways I'm thinking of something like this:
BugCorrection = PivotTable.VisibleFields(1).DataRange.Row - _
PivotTable.VisibleFields(1).VisibleItems(1).DataRange.Row
I have the following problem:
A datasheet with a column (HOUR) and another column (AM/PM). Entries in the first column consist of 1,2,3,4,5,6,7,8,9,10,11, or 12, the second column consists of 'AM's or 'PM's. Together they define the time of an incident (regarding the below problem, note that I am not allowed to create a new column in the source datasheet or change existing columns). The below formulas 1.) to 3.) work excellent for getting '1's or '0's for incidents that happened either between 8AM and 4PM, or outside of this time window, as long as I create a new column somewhere.
1.) =IF(AND(A1>=8, A1<=11),IF(B1="AM",1,0),0) + IF(AND(A1>=1, A1<=4),IF(B1="PM",1,0),0) + IF(AND(A1=12),IF(B1="PM",1,0),0)
2.) =--OR(AND(A1>=8, B1="AM", A1<>12), AND(OR(A1<=4, A1=12), B1="PM"))
3.) =--OR(AND(OR(A1={8,9,10,11}),B1="AM"), AND(OR(A1={1,2,3,4,12}), B1="PM"))
However, I want the "1"s to be summarized - without creating an extra column - as calculated field in a pivot table. While excel doesn't accept the 3.) formula at all in the calculated field option, excel accepts 1.) and 2.), but puts out only "0"s in all pivot cells. The below is one of the formulas that puts out only "0"s in the pivot table.
=--OR(AND(HOUR>=8,'AM/PM'="AM",HOUR<>12), AND(OR(HOUR<=4,HOUR=12),'AM/PM'="PM"))
The field value settings don't make a difference, and the fields that are created new with 1.) or 2.) cannot be filtered for "1"s or 0"s, so something must be wrong with the field calculation I guess. Does anybody know what I need to change to make it work? Are there special rules for formulas in pivot tables that apply to formula 1.) and 2.) to make them work?
Thanks for any help on this
I think the limitation is not you, but Excel.
See here for description of what is possible, as well as this question
I tried your code and indeed I see it's not working. Even with a simple if code it doesn't seem to work. I think it's is explicitly called a calculated field because you are only able to calculate the fields in the Sum/Total/Count etc. column.
Have a look at MS, this function is quite limited.
I would try to make another work-around to accomplish your goal.
Microsoft
The source data for my Excel PivotTable looks like the following (this is a simplification):
id name score
1 john 15
2 james 2
3 pat 14
4 jake 12
...
I have a PivotTable that uses this as a data source. Now, what I want to do is have the PivotTable only consider entries if their id is less than 100. This is theoretically achievable by having a Report Filter on id, and de-selecting any number greater than 100. But that's rather absurd.
How can I filter out data using a Boolean constraint? I've tried various methods, none of which worked. It seems like calculated fields are the key, but it doesn't seem possible to create a filter on calculated fields.
I'm using Excel 2011 for Mac, if that makes a difference. I'm a programmer, but I've never programmed in Excel, so if that's the solution, I'd request baby steps. :) Thank you!
AFAIK, In Excel 2011, you cannot use a report filter to apply any kind of filter. You have to manually check/uncheck the values that you want or don't want.
The alternative that I can think of is to insert a column before your data and enter the formula
=If(B2<100,TRUE,FALSE)
and copy it down using Autofill. (See screenshot below)
Now create a pivot and put the field "Less Than 100" in the report filter and simply select TRUE (See screenshot below)
If you don't want to go down that path then move the ID field to ROW LABEL from REPORT FILTER where you can use a filter.
A Report Filter is exactly what I would do, but rather than manually de-selecting the fields as you suggest you would do I would apply a Label filter to be less than the cut-off point, which in your example is 100.
I haven't used Excel on Mac, but on Windows on the PivotTable Field List, to the right of the id field click the little black arrow, and select Label Filters -> Less Than and then enter 100 in the dialogue that pops up.
Given the inherent value of PivotTables is the ability to apply filters exactly for this sort of scenario I don't think I'd do anything more complicated.