• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Weighted averages in PivotTable vs PowerPivot are not consistent|Power Pivot|Excel Forum|My Online Training Hub

You are here: Home / Weighted averages in PivotTable vs PowerPivot are not consistent|Power Pivot|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower PivotWeighted averages in PivotTable vs …
sp_PrintTopic sp_TopicIcon
Weighted averages in PivotTable vs PowerPivot are not consistent
Avatar
Gus Cops
Cambodia

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 13, 2023
sp_UserOfflineSmall Offline
1
March 13, 2023 - 7:44 pm
sp_Permalink sp_Print sp_EditHistory

Hi everyone,
I'm a new member, Excel power-user, intermediate level in PowerQuery/PowerPivot. I don't write code or macros, but I am good at looking at data and seeing inconsistencies linked to bad inputs or incorrect processing.
I'm on Excel 2013 with required add-ins, if it matters.

I've stumbled on a topic that is not frequently discussed online, and the answers are often over simplistic.
I'd love to hear from people with experience in this particular annoyance:
- I start with a table that holds items & quantity values, in columns. I'm interested in calculating sums & averages
- The difficulty is **weighted** average (eg average price paid for various purchases of different quantities of same item at different unit price). Most answers online cover straight averages, only.

Description:
1) a standard pivot table produces the subtotal sums by item, and a Calculated Field (price paid) / (quantity purchased) will produce
- the unit price paid per table line item. Not interesting & collapsed unless I want to drill down
- the subtotal row will show the sum of (price paid) and the sum of (quantity), AND Excel will use those 2 values for computing the ratio, which happens to be the correct, weighted average price paid. Great.

2) transpose this to PowerQuery/PowerPivot, and things go subtly wrong:
- I use PowerQuery to combine several data tables, and an output Connection (only) since I'm not interested in the long output table
- I use PowerPivot to "Manage the Data Model" and visualise the table. I have 2 options at this point:

a) add (in the memory table) a CalculatedColumn with the same formula above. Results in the table are fine.
I then create a pivot table, using that query as input. The line item averages are fine, BUT the rolled up subtotal calculates the average unit price of all the unit prices, NOT weighted. The average is calculated on the vertical axis / column only, even though the (sum of price paid) and (sum of quantity are correct). There is a valid number, but it doesn't have the correct average value!!!! (it's the unweighted average)

b) I do NOT create a CalculatedColumn, and instead I create a CalculatedField from the PowerPivot menu (the calculated field from the PivotTable menu is greyed out...). I use the same formula as above, and Excel returns an obscure error "Calculation error in measure.... The value cannot be determined."
This seems incorrect, since I use the built-in formula editor to avoid typos, and the formula produces valid results in scenario 1 and 2A.
I've been reading about Measure vs CalculatedField. I don't believe I'm doing (or need) a Measure.
My calculation is step-by-step, by row, only.
=> how can I get PowerPivot to work on row values at Subtotal level?

The easy way out for now is to skip PowerQuery/PowerPivot and just use a simple pivot table.
It bothers me to have all this computing power and still do things the old-fashioned way. 
Any suggestions?

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 613
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
March 13, 2023 - 10:04 pm
sp_Permalink sp_Print

A PP calculated field is a measure. All you need to do in PP is explicitly add the SUM function that a regular pivot table implicitly does (since it's the only function it will apply). So you would need:

=SUM(price paid) / SUM(quantity purchased)

in Power Pivot.

Avatar
Gus Cops
Cambodia

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 13, 2023
sp_UserOfflineSmall Offline
3
March 14, 2023 - 1:41 am
sp_Permalink sp_Print

Hello Velouria.

I learned something today, and at 57 that doesn't happen often 🙂
Measure it is, if you say so. I need to read more on that!

If anyone is reading this thread later, note that the reply above doesn't fully solve the issue.
What it produces is the "grand total weighted average of all unit rates"....across ALL items and ALL transactions.

The subtotals and individual unit rates appear ALL equal to the grand total value, which is not correct. And I can't drill down to check further. Some kind of filter condition needs to be added to group the sums by item name, and produce correct average weighted unit rate by item.
As I wrote in the intro, it's a subtle issue, and easy to get it wrong: a bad number looks as good as a good number if we're not paying close attention!

It seems like a lot of extra formula efforts to do, to produce the same results as the very easy option #1.
I'm sure there is a way, but I'll follow the path of least resistance for the moment.

Thanks for the lesson & tip

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 613
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
4
March 14, 2023 - 3:29 am
sp_Permalink sp_Print

From your description, I'd say your relationships are not set correctly, or there's an issue with which fields you are using in the pivot table. Filters only go from the one side to the many side in the relationship, not the other way in PP.

 

As an aside, PP is great when you have a well designed model and an absolute nightmare when you don't. As a general rule I find that the more complicated the DAX you have to write is, the more flawed your model.

Avatar
Gus Cops
Cambodia

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 13, 2023
sp_UserOfflineSmall Offline
5
March 14, 2023 - 1:28 pm
sp_Permalink sp_Print

Hi Velouria
Don't get me wrong, I am not trying to argue with you. I'm only replying for the sake of future readers, since I had so much difficulty finding good/definitive information on this thorny question:

- There is no relation setup in my case. Its a raw inventory list with 1 line per each item entry & purchase.
Single flat table with several columns. PowerQuery just appends several sources.

- I agree that a poorly designed model will lead to headaches. This is the reason why I struggle: my table is already normalised with values everywhere, repeated as often as required to make it very easy to analyse without worrying about relations.

- The likely answer to my PP question is something like SUMIF(item=XXX, price paid) / SUMIF(item = XXX, quantity purchased). I do NOT know the correct command or syntax, so future readers should read the manual if they want to explore further. The important point is that some kind SUM() function is required to satisfy the Measure criteria..

In my case, I am trying to avoid a SUMIF() scenario, it's not elegant for what I'm doing.
I was hoping to do better than a simple pivot table, but maybe PowerPivot is not a better tool for this scenario.

Avatar
Gus Cops
Cambodia

Active Member
Members
Level 0
Forum Posts: 5
Member Since:
March 13, 2023
sp_UserOfflineSmall Offline
6
March 14, 2023 - 2:19 pm
sp_Permalink sp_Print

Bing Chat provided another suggestion: stay with PowerQuery and Group rows according to item names, then add CalculatedFields for the unit rates.

It proposed a simple code example that does produce the correct summary Table, neatly.

Unfortunately, I loose the ability to drill down with this approach, so I'm back to old-school Pivot Table.

Avatar
Velouria
London or thereabouts
Moderator
Members


Trusted Members

Moderators
Level 4
Forum Posts: 613
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
7
March 14, 2023 - 7:59 pm
sp_Permalink sp_Print

If you only have one table, then a PP pivot should behave much the same as a regular pivot table. Any chance you can post a workbook?

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online:
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Ivica Cvetkovski
Blaine Cox
Shankar Srinivasan
riyepa fdgf
Hannah Cave
Len Matthews
Kristine Arthy
Michelle Neven
Andrew Kuhn
Angela Paul
Forum Stats:
Groups: 3
Forums: 24
Topics: 6206
Posts: 27202

 

Member Stats:
Guest Posters: 49
Members: 31875
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.