powerpivot using a calculated value in another calculation - excel

I have the following tables
Orders:
OrderID|Cost|Quarter|User
-------------------------
1 | 10 | 1 | 1
2 | 15 | 1 | 2
3 | 3 | 2 | 1
4 | 5 | 3 | 3
5 | 8 | 4 | 2
6 | 9 | 2 | 3
7 | 6 | 3 | 3
Goals:
UserID|Goal|Quarter
-------------------
1 | 20 | 1
1 | 15 | 2
2 | 12 | 2
2 | 15 | 3
3 | 5 | 3
3 | 7 | 4
Users:
UserID|Name
-----------
1 | John
2 | Bob
3 | Homer
What I'm trying to do is to sum up all orders that one user had, divide it by the sum of his goals, then sum up all orders, devide the result by the sum of all goals and then add this result to the previous result of all Users.
The result should be:
UserID|Name |Goal|CostSum|Percentage|Sum all
---------------------------------------------------
1 |John | 35 | 13 | 0.37 |
2 |Bob | 27 | 23 | 0.85 |
3 |Homer| 12 | 20 | 1.67 |
the calculation is as follow:
CostSum: 10+3=13
Goal: 20+15=35
Percentage: CostSum/Goal=13/35=0.37
Sum all: 10+15+3+5+8+9+6=56
Goal all: 20+15+12+15+5+7=74
percentage all= Sum_all/Goal_all=56/74=0.76
Result: percentage+percentage_all=0.37+0.76=1.13 for John
1.61 for Bob
2.43 for Homer
My main problem is the last step. I cant get it to add the whole percentage. It will always filter the result so making it wrong.

To do this you're going to need to create some measures.
(I will assume you've already set your pivot table to be in tabular layout with subtotals switched off - this allows you to set UserID and Name next to each other in the row labels section.)
This is what our output will look like.
First let's be sure you've set up your relationships correctly - it should be like this:
I believe you already have the first 5 columns set up in your pivot table, so we need to create measures for CostSumAll, GoalSumAll, PercentageAll and Result.
The key to making this work is to ensure PowerPivot ignores the row label filter for your CostSumAll and GoalSumAll measures. The ALL() function acts as an override filter when used in CALCULATE() - you just have to specify which filters you want to ignore. In this case, UserID and Name.
CostSumAll:
=CALCULATE(SUM(Orders[Cost]),ALL(Users[UserID]),ALL(Users[Name]))
GoalSumAll:
=CALCULATE(SUM(Goals[Goal]),ALL(Users[UserID]),ALL(Users[Name]))
PercentageAll:
=Orders[CostSumAll]/Orders[GoalSumAll]
Result:
=Orders[Percentage]+Orders[PercentageAll]
Download - Example file available for download here. (Don't actually read it in Google Docs - it won't be able to handle the PowerPivot stuff. Save locally to view.)

Related

Excel Pivot Chart - % Of Two Values

Let's say I have the following table:
CORP | COAST | CITY | DONE | MISSING | TOTAL
-------------------------------------
New | West | LAX | 2 | 4 | 6
Old | West | SFO | 3 | 3 | 6
New | East | NYC | 4 | 2 | 6
I make a pivot table that looks like this:
CORP:
COAST: NEW | OLD
-------------------------------------
EAST |
SUM OF TOTAL | 6 |
SUM OF DONE | 4 |
SUM OF MISSING | 2 |
WEST
SUM OF TOTAL | 6 | 6
SUM OF DONE | 2 | 3
SUM OF MISSING | 4 | 3
I want to now add a ROW that is the percentage DONE of the TOTAL amount. I.e. something like this:
CORP:
COAST: NEW | OLD
-------------------------------------
EAST |
SUM OF TOTAL | 6 |
SUM OF DONE | 4 |
SUM OF MISSING | 2 |
% DONE | %67|
WEST
SUM OF TOTAL | 6 | 6
SUM OF DONE | 2 | 3
SUM OF MISSING | 4 | 3
% DONE | %33| %50
The formula for % DONE is DONE / TOTAL
I've tried adding another DONE field to the pivot table (i.e. SUM OF DONE2) then setting the value to be % OF, the base field TOTAL and the base value (previous) however that makes % DONE return the value of #N/A. I've tried various combinations of the above however all are returning the same #N/A. I.e. my pivot table is looking like this:
CORP:
COAST: NEW | OLD
-------------------------------------
EAST |
SUM OF TOTAL | 6 |
SUM OF DONE | 4 |
SUM OF MISSING | 2 |
% DONE |#N/A|
WEST
SUM OF TOTAL | 6 | 6
SUM OF DONE | 2 | 3
SUM OF MISSING | 4 | 3
% DONE |#N/A| #N/A
I've tried Googling how to do it but still to no avail. Please let me know if what I am looking for is possible.
On the Analyze tab, add a Calculated field with the formula
= 'DONE'/'TOTAL'
There is an option in Pivot Table Options that allows you to show blank if there is an error, so you don't get an N/A for old/east. You can go into field settings and format the field as a percentage.

Show top 3 from list based on difference

I have 2 lists;
"yesterday" and "today".
As rows I have a list of companies and the data shown is customer satisfaction going from 0-10. I want to show the top 3 companies that has the best difference between "yesterday" and "today".
How would you approach this??
Expected output looking for top 1:
Yesterday - Today
Company A: 5 10
Company B: 7 8
Company C: 8 6
Top 1: Company A (Since they moved the most(5 positive points))
Assuming your data is like this:
#########Sheet1<YESTERDAY>########
| A | B |
1|Companies| Customer satisfaction|
2|Company1 | 6
3|Company2 | 3
4|Company3 | 4
5|Company4 | 1
6|Company5 | 9
###########Sheet2<TODAY>##########
| A | B | C | D |
1|Companies| Customer satisfaction|Absolute changes | RANK |
2|Company1 | 1 | | |
3|Company2 | 7 | | |
4|Company3 | 7 | | |
5|Company4 | 4 | | |
6|Company5 | 8 | | |
Put this formula into Cell C2to get absolute change:
=ABS(VLOOKUP(A2,YESTERDAY!$A$2:$B$6,2,FALSE)-B2)
Put this formula into Cell D2to get Rank:
=RANK(C2,$C$2:$C$6,0)
So, 1,2,3 in Column RANK are best changes.
I assume best difference as highest difference.run a loop and take the first row company from yesterday as well as the customer satisfaction value and search that same company in today in another inner loop and find the difference of the two values and save it in an array.After that sort the array and display the top 3.

How to filter data in pivot charts based on row contents

I don't even really know how to search for this, so I apologize if this has been asked already. I couldn't find anything.
I have data for a bunch of tests which is structured like so:
+---------+---------+-----------+-----------+
| TESTNUM | TEST_HR | CHEM1_HRX | CHEM2_HRX |
+---------+---------+-----------+-----------+
| 1 | 1 | 5 | 3 |
| 1 | 2 | 6 | 7 |
| 1 | 3 | 10 | 15 |
| 1 | 4 | 15 | 25 |
| 2 | 1 | 4 | 3 |
| 2 | 2 | 5 | 9 |
| 2 | 3 | 9 | 18 |
| 2 | 4 | 12 | 30 |
+---------+---------+-----------+-----------+
This chart is being pumped in by a database query, so I want it to be expandable and dynamic. It's basically two tests worth of chemical analysis, where a sample is taken every hour and tested. I cannot seem to wrap my head around a method of using a pivot table to display a scatter plot of TEST_HR and CHEM_1_HRX, and similar for CHEM_2_HRX. I had a method going using just tables, and it worked well, but required rework every time I updated the query to include more tests.
It seems that Pivot Tables don't support Graphing to XY (Scatter), bubble, or Stock chart types. But if you use line graph, and format the graph to remove the lines, it will look some what like a XY scatter graph.
Can you provide an example of what the chart should look like with the sample data you provided? (I would comment, but don't have enough rep points yet).

DAX TOTALYTD on two different cadandars

I am looking to create a YTD total, however, the year end date needs to change depending on the value in another column. In other words, the fiscal year for group 1 would be from 11-1 (Nov-1) to 10-31 (Oct-31), while the fiscal year for group 2 would be from 7-1 (Jul-1) to 6-30 (Jul-30). What I need to do is when calculating the fiscal year, I need the calculation for that year to be different depending on what group the line item is in. So 2015 for group 1 would be 2014-11-01 to 2015-10-31 while 2015 for group 2 would be 2014-07-01 to 2014-06-30. Please see an example table here (Please note that I do have a date table related to this one in order to create date functions):
**Table 1**
-------------------------
Group | Date | Qty
1 | 2014-10-01 | 1
1 | 2014-11-01 | 1
1 | 2015-01-01 | 2
1 | 2015-05-01 | 1
1 | 2015-10-31 | 2
1 | 2015-11-01 | 1
2 | 2014-06-01 | 1
2 | 2014-07-01 | 1
2 | 2014-12-25 | 2
2 | 2015-01-01 | 1
2 | 2015-06-30 | 2
2 | 2015-07-01 | 1
With this information in mind, I need to create a YTDTOTAL function that will dynamically change the , parameter depending on what group the line item is in. I thought of using an if statement, but realized that it wouldn't work on a measure. Something like this:
Total $ Sold YTD = TOTALYTD([TOTAL $ Sold],directSQLDateTable[date],ALL(directSQLDateTable[date]), IIF([GROUP = "A","10/31","6/30"))
In the end, I would like to create an output similar to this (The "Group A YTD" and "Group B YTD" columns really are not needed, just wanted to add to demonstrate my example):
Year-Month | Total_Qty | Group A YTD | Group B YTD
--------------------------------------------------
2014-07 | 1 | 0 | 1
2014-08 | 1 | 0 | 1
2014-09 | 1 | 0 | 1
2014-10 | 2 | 1 | 1
2014-11 | 2 | 1 | 1
2014-12 | 4 | 1 | 3
2015-01 | 7 | 3 | 4
2015-02 | 7 | 3 | 4
2015-03 | 7 | 3 | 4
2015-04 | 7 | 3 | 4
2015-05 | 8 | 4 | 4
2015-06 | 10 | 4 | 6
2015-07 | 5 | 4 | 1
2015-08 | 5 | 4 | 1
2015-09 | 5 | 4 | 1
2015-10 | 7 | 6 | 1
2015-11 | 2 | 1 | 1
2015-12 | 2 | 1 | 1
Please let me know if you have any questions. My apologies ahead of time if I didn't do that great of job explaining this or if I have left out a piece of info.
Thanks for any advice/help in advance! You guys on here are the best!
TOTALYTD() includes everything you need for this.
TotalQty:= SUM(Table1[Qty])
QtyYTDGroup1:=
TOTALYTD(
[TotalQty]
,DimDate[Date]
,Table1[Group] = 1
,"10/31"
)
QtyYTDGroup2:=
TOTALYTD(
[TotalQty]
,DimDate[Date]
,Table1[Group] = 2
,"6/30"
)
TotalQtyYTD:= [QtyYTDGroup1] + [QtyYTDGroup2]
I can provide a detailed explanation if you want, but I think the function definition pretty much covers it.

Week average pivot table in Excel

I have the following data on excel:
day | week | #pieces
1 | 1 | 5
2 | 1 | 5
3 | 1 | 5
4 | 1 | 5
5 | 1 | 5
1 | 2 | 5
2 | 2 | 5
3 | 2 | 5
4 | 2 | 5
5 | 2 | 5
1 | 3 | 5
2 | 3 | 5
I did a pivot table that gets the total of #pieces per week.
Now I want to get the average of #pieces per week. I tried to use a calculated field using #pieces/5 but this is not always true for the current week. See week 3 for example:
Week | Average #pieces
1 | 5
2 | 5
3 | 2 (this number '2' should be also '5')
Does anyone know how to do that?
Thanks
As far as I understand what you're trying to do, you don't need a calculated field (which is messing you up, by the way, because you're dividing by the hard-coded 5).
I would pivot with week number as your row label and average of pieces as your values. You can change sum to average in the value field options of the pivot table.

Resources