I am new to PowerPivot within Excel, but am familiar with SQL.
I import a table from my SQL server into PowerPivot, containing the results of some surveys; the columns are: City, State, Population, avg income, avg income x population.
I need to create a Pivot Table showing the weighted average income by State.
If the source of the data were an Excel sheet, I'd add a calculated field to the pivot table, calculating [avg income x population] / [Population].
I cannot seem to that in my case, since the source is a PowerPivot data source.
Suggestions?
I understand I can add calculated fields and measures to the PowerPivot table, but that's not really what I am after.
I am sure it's because my google skills are subpar, but I have also spent lots of time searching for solutions, to no avail.
E.g. these discussions show how to add a field to the powerpivot source, but it's not clear to me how you add a calculated field to a Pivot table which reads from PowerPivot.
PowerPivot formula for row wise weighted average
DAX - 2 phased weighted average with 2 different weight measures
Related
I am trying to calculate average of a min field using pivot tables. I can do it in 2 steps right now but was wondering if its possible to do in 1 step using the pivot table. Right now I have to do a min pivot table and then copy paste that into another table and do another pivot on it.
edit: I have uploaded sample here: https://easyupload.io/b6wvfd
Using DAX you could achieve it by using two measures:
First calculate the Minimum of the items, Min of item:
=MINX(Table1,Table1[age])
Then do average of the minimum values, Avg of Min:
=AVERAGEX(ALL(Table1[item]),
[Min of item])
Result should be like this:
Setup the PowerPivot Table
Transform your data into a table.
We can now create the PowerPivot and add the data to the data model
Then create a new measure by clicking your pivot table and then "Measures" -> "New Measure..."
Fill in all the relevant data and start with creating the "Min of item" variable.
Then create the average of min (since we use the previous measure in this function):
i got it to work using power query.:
Transform your table as table
load power query
do a group by region and sub and use min function
On that add a step to group by region and do the average
Overall goal for my report:
I am creating a pivot table in excel right now (eventually in Power Bi) that will update daily through data imports to reflect weekly changes in sales. I am then trying to perform a Z score analysis on each week to see if there are any outliers within the data.
What I will need to do is be able to subtract a mean of all of the data from each weekly set of sales, then divide it by the standard deviation.
Current thought process for data:
If I can get the grand total at the bottom, could I get that as a value entered for each row in another column? Can I do it as a total average and a total standard deviation? I can do it outside of a pivot table, but I want something in a pivot table so it auto-populates.
Current Data
Desired Data
You can tackle this in at least two approaches:
Dynamic calculation using measures
Back-end calculation
The first approach consists of defining measures in the following context:
CALCULATE([MEASURES], All('Calendar'), VALUES('Calendar'[Year]), VALUES('Calendar'[Month]))
This allows you to calculate a measure in a context that consider the entire month. Therefore, for each day you would have a measure that gives you the stdev of the entire month.
Pro: dynamic; fast to implement; can be based on measures already defined
Cons: more calculation in front-end slows down your report
The second approach consists of pre-calculating this values in the back-end. Here you have two possible approaches:
Data source: add these new columns in the data source (e.g. Database)
Pro: best-practices and clean approach
Cons: static; cannot use measures already defined
Calculated Column in DAX: define the value as a Calculated Column in the back-end of Power BI using the same structured defined for the Measure:
CALCULATE([MEASURES], All('Calendar'), VALUES('Calendar'[Year]), VALUES('Calendar'[Month]))
Pro: fast to implement
Cons: static; really against best-practices
In Power BI I used following measures (replace 'stack' with 'your table name')
Total StdDev = CALCULATE(STDEV.P(stack[sum of sales]), ALL(stack))
TotalMean = CALCULATE(AVERAGE(stack[sum of sales]),ALL(stack))
Z score = (SUM(stack[sum of sales]) - [TotalMean])/[Total StdDev]
I used average to calculate MEAN and I get different result to yours (please see below).
If you can share formula that you used to calculate 'TotalMean' maybe I can update it.
So I have this small data set:
Pivot table
A has 9 total players and total cost is 32 so average cost of a player on team A should 32/9=3.55. But the the pivot table says its 3 which obviously wrong. How do I get the right answer on the pivot table.
This sounds like a math problem. You are taking the Average of "Average Cost" and the average of averages is not usually the "average" you are looking for. I would say try taking the sums of ALL of each team's players and costs prior to averaging.
Restructuring your base data will be the easiest way to get your PivotTable to display the average you are hoping for.
I am having issues translating the following formula to a pivot table; either through a regular pivot table, or through DAX and powerpivot.
=SUMPRODUCT((C$2:C$11)*(D$2:D$11)*(A$2:A$11=A2)*(B$2:B$11=B2))/SUMIFS(D$2:D$11,A$2:A$11,A2,B$2:B$11,B2)
The background is, I have a number of products that appear on an e-commerce site, and I need to find out their price per day. However, these prices change daily, based on things like promo codes, visitor location etc. Therefore, I need their weighted price based on the number of visitors that saw a particular price.
Can anyone help with this translation, or alternatively, offer a better way to approach this problem?
PS- I need it in a pivot table due to the volume of data. At 250,000 rows, standard Excel cannot handle this formula.
The following is in Excel 2010 sans Powerpivot. However, the general approach should work:
Explanation:
I added a column that multiplies the Prices and Visits. The pivot table uses Dates, then Product SKU as the row labels. Then I added a calculated field that divides the Price*Visits by the Visits.
I'm trying to get the average number of "on time shipment" based on items rolled up to "ship numbers" and then by "order number". I have one order number in this scenario that is shipped via multiple shipments. It seems to me that after rolling it up via PowerPivot and then creating a pivot table, it's calculating the average based on the total lines of the "order number" instead the pivot.
PowerPivot Data:
Pivot based on data above:
How can I get the average number based on the pivot table rather than the PowerPivot total data of the order number? I'm probably not making any sense, but hopefully the images below explain it better. As you can see, when you roll up the items by ship number then by order number, you'll see that the actual average is 0.6 but the pivot is showing 0.5.
Help!
Technically speaking, the average is correct - if you look at the source data, for some reason all rows are duplicated and if you do regular average calculation, it's actually 0.5.
What you are looking for is calculating average for distinct values, which can be done easily with AVERAGEX function.
I have copied your table and created those 2 Calculated Fields (in Excel 2010, it's Measures):
Average on Time:
=AVERAGE(Table1[On Time])
Average on Time (UNIQUE)
=AVERAGEX(VALUES(Table1[Ship Number]), [Average on Time])
Using AverageX with VALUES() function makes it easier to calculate any expression ONLY for unique values.
If you then put both measures on PivotTable, you should get this:
First column is same as yours (using "regular" AVERAGE function). The second one shows the average calculated over distinct (unique) values of Ship Numbers.
Hope this helps.
PS: This great article by Kasper de Jonge helped me quite a bit with similar scenarios.