Percentage graph from absolute values - excel

I have the following data:
Date A B C
2012/07 7 6 0
2012/08 9 4 0
2012/09 9 3 0
2012/10 14 2 1
2012/11 9 16 0
2012/12 0 14 0
2013/01 7 9 1
2013/02 8 13 1
2013/03 16 62 16
2013/04 7 12 4
2013/05 10 11 1
2013/06 6 37 4
I want to make a line graph from these data, but I want it to show percentages of line total (A + B + C) instead of the absolute values. How can I do this directly, without resorting to intermediate cells where I'd insert formulas to calculate the percentages or adding a line total column?
So the end result should look like this:
But I don't want to have to "manually" create cells like these:
A B C
2012/07 54% 46% 0%
2012/08 69% 31% 0%
2012/09 75% 25% 0%
2012/10 82% 12% 6%
2012/11 36% 64% 0%
2012/12 0% 100%0%
2013/01 41% 53% 6%
2013/02 36% 59% 5%
2013/03 17% 66% 17%
2013/04 30% 52% 17%
2013/05 45% 50% 5%
2013/06 13% 79% 9%

Use Named Ranges.
First, define the name "Total" as =B2:B12+C2:C12+D2:D12
Then, define three names "PctA"=B2:B12/Total, PctB etc.
Then, define a name "Dates"=A2:A12
Insert a line chart and enter the 3 pct names as the data series. Put in the names as Sheet1!PctA, etc. - Excel won't accept the names without a sheet reference.
Do same for Dates as the horizonal category range.

Related

How to do SUMPRODUCT with percentage and blank cells

I am trying to do SUMPRODUCT in Google Sheets but in a more complicated situation.
I want to sum product with percentage instead of decimal number.
This is what I am doing now, and it works just fine:
A B C D
Price Tax Cashback
100 1.09 0.95
80 1 1
50 1.09 0.95
Total =SUMPRODUCT(B:B, C:C, D:D)
What I actually want to do is
A B C D
Price Tax Cashback
100 9% 5%
80
50 9% 5%
Total ???
Use
=SUMPRODUCT(B2:B, 1+C2:C, 1-D2:D)

Excel: Match and Index based on range

I am stumped with the following problem and not sure how to accomplish it in excel. Here is an example of the data:
A B
1 Date Stock_Return
2 Jan-95 -5.2%
3 Feb-95 2.1%
4 Mar-95 3.7%
5 Apr-95 6.9%
6 May-95 6.5%
7 Jun-95 -5.6%
8 Jul-95 6.6%
9 Aug-95 6.2%
What I would like is to have the dates returned which fall within a certain return range and sorted from low to high.
For example:
1 2 3 4 5
Below -7% 0 0 0 0 0
-7% to -5% Jun-95 Jan-95 0 0 0
-5% to -3% 0 0 0 0 0
-3% to 0% 0 0 0 0 0
0% to 3% Feb-95 0 0 0 0
3% to 5% Mar-95 0 0 0 0
5% to 7% Aug-95 May-95 Jul-95 Apr-95 0
I thought Index and Match might make the most sense but when I drag across columns it doesn't work. Any help is very much appreciated.
You can use AGGREGATE function:
=IFERROR(AGGREGATE(14,6,$A$2:$A$9/(($B$2:$B$9>$D2)*($B$2:$B$9<=$E2)),COLUMN(A1)),"0")
If you have Excel O365, you can use the FILTER function:
F2: =IFERROR(TRANSPOSE(FILTER($A$2:$A$9,(F2<=$B$2:$B$9)*(G2>=$B$2:$B$9))),"")
and fill down.

Can not replace values in pandas dataframe column with map

I'm trying to replace a column in pandas data frame using a dictionary and the map method.I found a method without map but its very very ugly
Here is my dictionary
{'A+': '97–100%',
'A': '93–96%',
'A−': '90–92%',
'B+': '87–89%',
'B': '83–86%',
'B−': '80–82%',
'C+': '77–79%',
'C': '73–76%',
'C-': '70–72%',
'D+': '67–69%',
'D': '63–66%',
'D-': '60–62%',
'F': '0–59%'}
and here is my data frame
Fname Lname MidExam FinalExam CW1 CW2 TotalPoints StudentAverage Grade
1 Velma Paul 49% 66% 59% 78% 252 63.00% D
2 Kibo Mcgee 75% 75% 68% 66% 284 71.00% C-
3 Louis Underwood 98% 44% 67% 42% 251 62.75% D-
4 Phyllis Clemons 65% 45% 65% 55% 230 57.50% F
5 Zenaida Mcdowell 65% 54% 65% 54% 238 59.50% F
and i want to replace the letters D, F, ... with numbers
After i use
df["Grade"] = df["Grade"].map(usa_grade_dict)
i get
Fname Lname MidExam FinalExam CW1 CW2 TotalPoints StudentAverage Grade
1 Velma Paul 49% 66% 59% 78% 252 63.00% NaN
2 Kibo Mcgee 75% 75% 68% 66% 284 71.00% NaN
3 Louis Underwood 98% 44% 67% 42% 251 62.75% NaN
4 Phyllis Clemons 65% 45% 65% 55% 230 57.50% NaN
5 Zenaida Mcdowell 65% 54% 65% 54% 238 59.50% NaN
I do not know why I am getting NaN instead of the actual number
Any help would be awesome ^^ Ty
If get missing values in output it means key of dicionary not match with values of column.
If problem with whitespaces in column use Series.str.strip:
df["Grade"] = df["Grade"].str.strip().map(usa_grade_dict)

Ranking, treat a negative number as zero

Is there a way in Excel when ranking to treat a negative number as zero?
I have the following, but if I have multiple zeroes or negatives, I end up with duplicated ranks, which I cant have. I end up with:
1 2 3 4 5 6 7 8 8 8 9 10 11 12 13 14 15 16 ... 55
but i need
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ... 55
=IF($S79<0,RANK(0,$S$68:$S$121,0)+COUNTIF($S$68:$S79,0)-1,RANK($S79,$S$68:$S$121,0)+COUNTIF($S$68:$S79,$S79)-1)
Edit for clarification:
At the moment I have 55 rows. Rows 1-20 usually have a positive number, with the rest being zero. When I have a negative number, instead of it being placed in spot 21 (underneath all the positive numbers), it gets placed in spot 55 (because its less than zero).
So instead of
1 - 43%
2 - 35%
3 - 22%
4 - 0%
5 - 0%
6 - -20%
I'm after
1 - 43%
2 - 35%
3 - 22%
4 - 0%
5 - 0%
6 - 0% (treating the negative as zero, but visually still displaying the negative number)
Its for a weighted percentage leaderboard. I found a workaround by just adding a check for the percentages, something along the lines of "if % < 0 then 0 else %. Not exactly what I was after, but it will do. It stops people in the negative being placed at the bottom of the list i.e. spot 55.
I was getting:
1. Person 1 - 100%
2. Person 2 - 90%
3. Person 3 - 90%
4. Person 4 - 0%
5. Empty Slot - 0%
6. Empty Slot - 0%
7. Empty Slot - 0%
8. Person 5 - -50%
I want:
1. Person 1 - 100%
2. Person 2 - 90%
3. Person 3 - 90%
4. Person 4 - 0%
5. Person 5 - -50%
6. Empty Slot - 0%
7. Empty Slot - 0%
8. Empty Slot - 0%
Settled for (by adding a check where the % is generated):
1. Person 1 - 100%
2. Person 2 - 90%
3. Person 3 - 90%
4. Person 4 - 0%
5. Person 5 - 0%
6. Empty Slot - 0%
7. Empty Slot - 0%
8. Empty Slot - 0%
I think you may just need the LARGE function. You can use this formula:
= MAX(LARGE($A$2:$A$10,ROW()-ROW($A$2)+1),0)
(But just change these ranges to whatever your ranges are)
See below for an example. Column A contains the data and column B sorts the data with the largest at the top, and considers any negative numbers as just 0.

Excel - running % of running total in pivot table

I have a table like:
periodo quintil pos
201611 1 10
201611 2 20
201611 3 30
201611 4 40
201611 5 50
201612 1 9
201612 2 19
201612 3 29
201612 4 39
201612 5 49
I need to create a pivot table like:
periodo quintil running_pos running_%
201611
1 10 7%
2 30 20%
3 60 40%
4 100 67%
5 150 100%
201612
1 9 6%
2 28 19%
3 57 39%
4 96 66%
5 145 100%
Since the running total is not a new field, but a way to show an older field (pos- show as total in quintil), the problem arises when I try to create the running % of the running total.
How can I introduce also this field (running % of running total)?
In spanish there's nothing with a name like running totals translation....
To display what you want in a Pivot Table
- Drag pos to the values area three times
- For the first, use the SUM
- For the second, use the "show as running total"
- For the third, use the "show as % running total"
Here are the results with minimal formatting
Here are the value settings for the third column:

Resources