I am trying to use an if statement in excel measures for powerpivot tables. I am trying to calculate revenue per unit but I have one Product Line that calculates revenue differently than all the other Product Lines. The equation I am trying to use is =IF(tableA column = "certain Product Line", calculated revenue for PL/calculated units for PL, calculated revenue for all other PLs / Calculated units for all other PLs). For some reason I keep getting the error "Calculation error in measure, a single value for column 'PRODUCT_LINE' in table 'A' 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".
Related
I have data in below format. It shows starting and end time of an activity and calculates duration accordingly. The activity is performed through out the day at different times.
I have added a pivot. I want to find out the average duration in a workday or a holiday(Day category). When I am trying to apply average in the current pivot, it is dividing the total duration by the number of sessions in a day.For example in week 1, an activity was done on 4 work days and the total duration for the activity in workdays was 04.19, I want to divide this number by 4 and find out the average time spent on each day but the pivot divides it by 11 which is the total number of sessions in the four days.
Link for data
Steps:
Add a helper column to identify how many unique pairs of Dates/Day Categories there are:
=IF(SUMPRODUCT(($A$2:$A2=A2)*($B$2:$B2=B2))>1,0,1)
You can add extra products to this formula to force extra fields to be unique to be counted as well.
SRC:Simple Pivot Table to Count Unique Values
Add a Calculated Field in the PivotTable that is:
SUM(Duration)/SUM([Helper Column Name]) and include it in the 'Values' section of the PivotTable. Due to the new column being added, you might have to re-create the PivotTable.
This should produce the average in the manner that you want.
Here, I have some vehicle data, attached with some corresponding information about the where the owners of these types of vehicles live, and their average house price.
Clearly the house price/location doesn't directly affect the vehicle value, but is useful for statistical inference.
What I want to do is to create a pivot table - however when considering the average vehicle value, the pivottable sums up each type of Vehicle/Model class multiple times as shown below:
And so, while the average House Price column in the pivottable is correct, the vehicle value is incorrectly counted multiple times (with respect to the Vehicle Make).
No, there is no DistinctSum function in the pivot table. The only thing that comes to mind is to add an additional column in the base table where the required values can be calculated. For example, in the column 'Distinct value' you can insert the following formula:
=D2/SUMPRODUCT((A2=$A$2:$A$13)*(B2=$B$2:$B$13))
it calculates the Value / Count of values for each car and model and then in the pivot table sum this column.
Can I define different aggregation methods for subtotals in different dimension in an Excel pivot table?
The following example shows a result I'm trying to obtain. The metric to aggregate is, let's say, lines of code of a software project. The 2 dimensions in question are Date and Organization. In source data, Organization is broken down into 2 columns, Department and Project, while Date is a single column and Excel makes up the Months/Years summaries automatically when making the ODBC data connection.
A metric such as this one should be aggregated differently along the different dimensions. For the Organization dimension, the subtotal for all projects of the department is the SUM, but in the date dimension, the subtotal for all months of the year is the MAX of any given month (or perhaps AVG, or last etc. but certainly not SUM).
I've tried to define the different aggregation methods in Excel in the field settings, but it always selects one or the other method for both dimensions. Is there a way to do it, preferably using standard Pivot Table mechanisms or at worst a UDF in Excel?
What I would do to tackle this problem is to add both aggregation functions: sum and max , then hide ( or shrink a lot ) those columns you do not want to display.
in the above example I shrink columns B,D,F and I because of they has values that are out of scope for your requirements.
The "Total Max of Loc" displays a value consistent with the function expressed throughout the entire column: that is "the maximum number of lines of code reached by each project in each department; this could lead to misunderstandings when we observe the values of the subtotals and grand total; i.e: The "Grand Total - Total Max of Loc" is not the "Total Max of Sum of Loc": in the example, it shows 18 which represents the absolute maximum value of Loc in a Project in each Department; In the same way the Total Max of Loc for Department 2 is 18 and form Department 1 is 12
When requested a different behavior as expressed in comment to this answer, I think we are entering into the strong customizations space and some solution could be found by writing custom macro and by leveraging the getpivotdata function or, if it can be acceptable for your case, simply by the addition of a new column with the max()formula and possibly hiding the column "Total Max of Loc"
I have created a PowerPivot Report which contains a Price field and a Sales as well as a Measure column.
Price Column will obviously contain the unit price
Sales Column will give the units sold
Measure Column is the measure of the product.
From this I have a:-
Total Price which is PricexSale and a
Total Measure which is MeasurexSale
In the calculation section I have then worked out a calc which is Simply
Unit Per Thousand:=SUM(Products[Total Price])/SUM(Products[Total Measure])*1000
The issue I am getting is this is rounding it to the nearest 10 So rather than £17.88 it is displaying £17.90. It is set to 2 decimal places already. All the values in the columns are correct to the 2 decimal places. Can anyone assist to get me the correct result and not a rounded result.
It sounds like you need to use the round function in DAX on your measure which would allow you to round the result of the calculation. This being different then setting the field's format settings.
It would be
ROUND(<number>, <num_digits>)
Link to Microsoft site on the function:
enter link description here
Edit:
Then it sounds like you want to use the trunc function in DAX to truncate the number after a certain number of significant digits.
TRUNC(<number>,<num_digits>)
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.