Excel Pivot table how to get average of a min field - excel

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

Related

PowerBI DAX: logic to use aggregated table as parameter in functions or another workaround to calculate dataset KPI filtered by any field?

In PowerBI, I need to create a Performance Indicator (KPI) measure which evaluates dataset values in a scale from 0 to 1, with target (1) being the MAX value in a 20 years history. It's a national airport trip records open database. The formula is basically [value]/[max value].
My dataset has a lot of fields and I wish I could filter it by any of these fields, with a line chart showing the 0-1 indicator for each month based on the filters.
This is my workaround test solution:
Table 1 - Original dataset: if I filter something here, below tables also update (there are more fields to the left, including YEAR and MONTH
Table 2 - Reference to original dataset, aggregating YEAR-MONTH by the sum of "take-offs" (decolagens)
Table 3 - Reference to above (sum) table, aggregating MONTH by the max of "take-offs" (decolagens)
Table 4 - 'Sum table' merged to 'Max table' by MONTH as new table: then do [Value]/[Max] and we've got the indicator
So if i filter the original dataset by any fields, all other tables update accordingly and the indicators always stays between 0-1, works like a charm.
TL;DR
The problem is: I need to create a dashboard of this on Power Bi. So I need this calculation to be in a measure or another workaround.
My possible solution: by pure DAX code in the measure field, to produce Tables 2 and 3 so I'll divide the month sum values by their month max value (which will both be produced according to PowerBi dashboard slicers) and get the indicator dinamically produced.
I'm stuck at: I don't understand how can I reference a sum/max aggregate table in dax code. Something like = SUM (dataset[take-offs]) / MAX (SUM (dataset[take-offs])). Of course these functions do not work like that, but I hope I made my point clear: how can I produce this four table effect with a single measure?
Other solutions are welcome.
Link to the original dataset: https://www.anac.gov.br/assuntos/dados-e-estatisticas/dados-estatisticos/arquivos/DadosEstatsticos.csv
It's an open dataset, so I guess there's no problem sharing it. Please help! :)
EDIT: please download the dataset and try to solve this. Personally I think it's a quality statistics doubt that will eventually help others. The calculation works, it only needs a Power Bi Measure port.
Add the ALL formula:
Measure = SUMX(ALL('Table'),[Valor])/SUM('Table'[Max])
Example

How To Convert The Grand Total of a Pivot Table as a Value for Each Row in a New Column

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.

PowerPivot: how to calculate a weighted average in a pivot table?

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

Overcoming System Limits When Using Pivot Table

I am trying to make a pivot table that has a list of inventory on one axis and customers on another axis. With this table I could replace all non-'1' values in the table with 1s and then use the column count to determine the total number of items purchased by each customer. However, Excel claims that there's far too much information and that it wouldn't be able to complete the task. Is there another way to do this that doesn't involve pivot tables?

Getting only top 10 values from an Pivot table

I have created some pivot tables which shows sales of PC from different brands for multiple years. for example 2013 PC sales of dell,HP,Apple etc...
Now I want to compare these sales but I just want to compare top 10 results...I am trying to create a table which will show only the top ten values from the pivot table. I dont want to filter the pivot table to top 10 values.
Thanks and Regards
If you have to create your output as a table without filtering the pivot table, you can use cube functions. Create a cubeset that is all PC brands and order them by PC Sales. Create cubrankedmember functions for positions 1 through 10. Then write a cubevalue formula next to each cuberankedmember to retrieve the associated value. If you want to post a little more about your data model, I could write more specific cube function formulas.

Resources