DAX for MAX of a group - visual-studio-2012

I have two data columns:
Record | Record Version
------------------------
1 | 1
1 | 2
1 | 3
2 | 1
2 | 2
2 | 3
2 | 4
3 | 1
3 | 2
3 | 3
4 | 1
4 | 2
4 | 3
4 | 4
4 | 5
4 | 6
5 | 1
6 | 1
Is it possible to create a calculated column within a MVS-2012 model or PowerPivot that will give the MAX of the Record Version for a corresponding Record? For example the MAX value of Record 1 is 3, MAX value of Record 2 is 4 etc.

Yes. Add that table to your Power Pivot model, either by pasting the data into Excel and then clicking Add to Data Model on the Power Pivot ribbon, or by opening the Power Pivot Window and adding it form it's original source there.
In the Power Pivot window, go to the table where this data is located.
Select the Record Version column, then click the drop-down next to AutoSum in the Calculations group on the Home tab and choose Max.
A calculated column will appear at the bottom. YOu can rename it to something like Max Record Version.
Make a PivotTable in Excel (click the PivotTable button on the Home tab).
Add the Record field to rows and the Max Record Version to values.
If you actually want a calculation that will give you the max for the group of record you could do something like:
=SUMX(VALUES(Table1[Record])
,CALCULATE(MAX(Table1[Record Version]))
)

Generally, as #mmarie suggests, you are better dealing with this kind of problem with a measure rather than a calculated column. That said, sometimes you just need that extra column (usually to use as a dimension).
Assuming you have a table called recordsFact, this gives the MAX of that record:
= CALCULATE(MAX(recordsFact[Record Version]),
FILTER(recordsFact, recordsFact[Record] = EARLIER(recordsFact[Record])
))

Related

Pivot Table considers duplicate elements for the average calculation

I have a pivot table (with Data Model) based on below table
Id | Time
1 | 10
1 | 10
1 | 10
2 | 2
3 | 5
3 | 5
4 | 4
5 | 8
I need to calculate the average of time.
Average based on the pivot table calculation is 6.75 --> (10*3+2+5*2+4+8)/8
However, my expected result is 5.8 --> (10+2+5+4+8)/5
How can I setup the pivot table to not take into consideration the duplicate ?
Please note that I can't remove duplicate rows.
I tried to use AVERAGEX : =AVERAGEX(VALUES('Range'[Id]);'Range'[Time]) with DAX.
But I'm facing this issue: This formula is invalid or incomplete: 'Calculation error in measure 'Range'[475e7fe7-92b4-478c-bd5f-6e7c95df27d7]: A single value for column 'Time' in table 'Range' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.'.
Thank you in advance !
Solution
=AVERAGEX(VALUES('Range'[Id]);CALCULATE(AVERAGE('Range'[Time])))
Solution
=AVERAGEX(VALUES('Range'[Id]);CALCULATE(AVERAGE('Range'[Time])))

Sort this data in excel kinda like a pivot

All,
I have this data I pulled from a database that I need to readjust. Here it is:
ID | Type | total
1 Purchase 12
1 Return 2
1 Exchange 5
3 Purchase 34
3 Return 4
3 Exchange 2
The desired result is:
ID | Purchase | Return | Exchange
1 12 2 5
3 34 4 2
and so on with a lot more data. Can this be done?
In Excel, format the data like so:
Choose a cell in these data, go to Insert -> PivotTable, insert it where you would like, and use the following settings:
This gives
Under "Design" in the Ribbon (make sure that your PivotTable is selected), go to Grand Totals -> Off for Rows and Columns. This gives
Click the "Exchange" cell and go toward the top of it, right below the "Column Labels" cell - you will see that the arrowhead will change and you can drag the column:

Excel 2013 grid lookup generate SQL

I have an excel sheet that needs exporting into MYSQL. This sheet contains a grid with the rows being components and columns being products.
Column A holds the component name with columns b onwards using row 1 as product names.
The grid is a grid of components that make up that product in row 1 of the column. not all components are used in a product, for example:
xxxxxxxxxxx | product 1 | product 2
component 1 | 1 | 0
component 2 | 0 | 1
component 3 | 0 | 10
and so on. I am trying to get a formula that can check each column against each row, if the column has a value > 0 or not blank then grab the product name, component name and the value ready to be used to generate SQL (i already have component ids etc)
is this possible? I have seen reverse lookups and lookups using grids but not to this level..
would be very grateful to any excel wizards out there that can save me hours of manually doing this (there are 102 products with ~ 1000 different components..)
Perhaps what you want is described here followed by filter to delete rows with Value 0.

Executing a function over a grouped set

I have two columns of data in Excel, one containing dates and the other values 1 or 2 which represent a specific status (like an enum).
Here is an example data set:
2014/07/04 | 1
2014/07/04 | 1
2014/07/04 | 2
2014/07/04 | 1
2014/07/05 | 2
2014/07/06 | 1
2014/07/06 | 1
2014/07/06 | 2
I need to get a graph of the percentages of the number 1 over days; in the above example
July 4th: 75%
July 5th: 100%
July 6th: 66%.
I've tried pivot tables and charts with no luck because I can't write my own function for values (COUNTIF for ones divided by COUNT), only use the predefined ones which aren't of any use.
Does anyone know how I would go about doing this?
You could do this with a pivot chart.
I made up my own data so it doesn't quite match but it is the same idea.
For the pivot table fields I used
Legend Fields:Compare
Axis Fields:Date
Values: Count of compare
For values under Value field settings goto show value as and change this to % of column total and summarize value by Count.
If you only want to see number one just put a filter on the column labels.

Percentage of Sum of two Pivot cells

I'm trying to work out a small problem with my excel Pivot table. I have data from a Excel Sheet which i have made a Pivot table of. The data is structured as below
Name | Count Cell1 | Sum of Cell 2 |
Eric | 25 | 5 |
Sam | 5 | 1 |
Joe | 10 | 5 |
What i want to have is a formula that takes the Count of Cell 1 and divide it by Sum of Cell 2 and display it in % like the example below.
Name | Count Cell1 | Sum of Cell 2 | Difference|
------------------------------------------------
Eric | 25 | 5 | 20% |
Sam | 5 | 1 | 20% |
Joe | 10 | 5 | 50% |
All formulas i have tried only uses the original Table cells and not the sums of them.
So is there a smart way to have a formula lookup inside of a pivot table and display it in %?
In your Pivot Table, you can enter a calculated field to do what you want.
Select somewhere in your pivot table (e.g. one of the Sum of Cell2 fields)
In the PivotTable Tools > Options ribbon, in the Calculations section, click Fields, Items & Sets and from there pick Calculated Field
Change the name to Difference and the Formula =Cell2/Cell1
In the Field Settings for that field, change the Custom Name to Difference and Number Format to Percentage
EDIT - question updated for Count & Sum
So, as far as I can see, trying to do the combination of Sum/Count really upsets it... the only workaround I could find was adding a helper column in the data source with just the number 1... in that way, the sum of that gives you the count, and so the Calculated Field can be Cell2/HelperColumn -horrible!

Resources