calculating stock market bonus shares

mwvirk

Active Member
Joined
Mar 2, 2011
Messages
293
Office Version
  1. 2016
Platform
  1. Windows
hello

I am calculating how many bonus shares (Flag marked as B) I have received from the stock market for each of my stocks
and then also checking if I sell some bonus shares then how many are still in my portfolio

in this excel file, I have 2 sheets
sheet1 is for buying, selling and bonus shares received
sheet2 is to check the status that how many bonus shares were received and how many are left. if all are sold then I should get 0 in sheet2 cell D
(but in all cases, I want to keep the actual bonus shares received in sheet2 cell C)

I have multiple issues here in this sheet2:

1- if the cell H in sheet1 is blank then cell D in sheet2 is not counting the total (i should have a value of 0 at least in sheet1 cell H to get the result since the blank cell is not showing the count in sheet2 cell D)
2- if I partially or fully sell bonus shares in sheet1 then it's showing balance zero in all cases in sheet2 cell D (i am checking here to know how many are still in my portfolio)

kindly check and help.

thanks


Test-Copy.xlsx
ABCDEFGH
1Stock nameFlagReceivedSold
2AppleR1000
3GoogleR1500
4IntelR2000
5FacebookR2500
6AppleB105
7GoogleB150
8IntelB200
9FacebookB250
10AppleR2000
11GoogleR2500
12IntelR3000
13FacebookR3500
14AppleB15
15GoogleB20
16IntelB25
17FacebookB30
Sheet1





Test-Copy.xlsx
ABCD
1Apple250
2Google3515
3Intel4520
4Facebook5525
Sheet2
Cell Formulas
RangeFormula
C1:C4C1=SUMIFS(Sheet1!F:F,Sheet1!A:A,A1,Sheet1!C:C,"B")
D1:D4D1=SUMIFS(Sheet1!F:F,Sheet1!A:A,A1,Sheet1!C:C,"B",Sheet1!H:H,0)
 
Thank you...that helps. I was clear on most of this. But my question is not about the structure of a candidate's name or the party. Rather the question is about whether the same candidates must appear on the ballots in all of the numbered areas for the same two-letter code. For example, if Michael Steven John appears on the ballot for NA-001, must he also appear on the ballot for NA-002, NA-003, NA-004, etc.,..or is it possible that each numbered area has a slightly different list of candidates? I am asking this because it changes how a combination table needs to be built, or whether this approach is even viable. If exactly the same candidate/parties appear on the ballot for each NA numbered area that becomes easier to do because the candidate/party group for every NA# would be the same, and this repetition could be handled automatically. But if the candidates can vary among different NA#'s, then this idea would not work. I am not sure you have answered this specific question but I think that perhaps the candidates can be different among different NA#'s?
 
Upvote 0

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
if Michael Steven John appears on the ballot for NA-001, must he also appear on the ballot for NA-002, NA-003, NA-004, etc
if Michael Steven John appears for NA-001 then there are chances that he can be in any other NA multiple times. It may be in NA-002 as well
it is not important that if he is in NA-001 then he MUST appear in NA-002 - it can be any random number
he can be in NA-001 and might be in NA-002 as well as in any other NA e.g. (NA-001 - NA-002 - NA-007 - NA-090 - NA-180 - NA-200 - NA-260 any NA)
he can be in NA-001 - NA-002 - NA-010 - NA-240 - NA-260 and the same time in PP-001 - PP-020 - PP-100 - PB-003 - PB-010 - PS-100 - PS-200 - KP-020 - KP-150 - KP-200

suppose you are in America (Country). and you have multiple states New york, New Jersey, Chicago, Baltimore, and Washington (for me these are NA)
now in Baltimore (NA), you have multiple areas. Maryland, ABC, DEF, XYZ (for me these are provinces)

now KRice is a candidate for the Republican Party. now KRice is participating on behalf of the Republican Party from different NA (New York and Baltimore etc)
then KRice is also a candidate for the Republican Party from Maryland (the name is anything in my case. it can be PP PB PS KP)
then KRice can also be a candidate for the Republican Party from any area (province) of the New York

any party is having maximum winners from NA will be the rolling party in the country
any party is having maximum winner from PP will be the rolling party for the country for that province PP only
any party is having maximum winner from PS will be the rolling party for the country for that province PS only
any party is having maximum winner from PB will be the rolling party for the country for that province PB only
any party is having maximum winner from KP will be the rolling party for the country for that province KP only
 
Upvote 0
if i have 300 NA#
and each NA# i am assuming 30 candidates
then physically there will be 9,000 candidates

same applies for PP PB PS KP
 
Upvote 0
Thank you...that clears up my question. So constructing combinations--like I was envisioning--will not work because the ballots (the list of candidates and their parties) for the NA#'s could differ from one NA# to another. Wow!...constructing your initial list of candidates/parties becomes very messy, as each ballot (for each NA#) may differ. I think what confused me was the initial example where Candidate Name 001, etc. appeared for each NA# and I assumed "Candidate Name 001" referred to a specific person or every ballot (for NA-001, NA-002, etc.), rather than being a placeholder for different candidates.
 
Upvote 0
Do you think we should roll back the recent changes? since it's taking full CPU utilization and taking a long time to just input 1 single cell?
- We can remove the newly inserted row 'J'
- un-merge the A row and either uses NA# once on top of the record A2 for NA-001 and then A32 for NA-002
- un-merge O P Q R and keep the winner name on O2 for candidate name for NA-001 P2 for party name then Q2 R2 and for the next record (NA-002) use the O32 P32 Q32 R32
- remaining cell O3:O31 P3:P31 Q3:Q31 R3:R31 can be ignored or anything for not being used?

earlier we were having issues that everything was working fine but only the condition check was not working.
now everything is perfect and working fine but the system is hanging with just 1 sheet of 8161 rows
 
Upvote 0
I believe my earlier idea about using repetition of a candidate list to populate the vote tabulation table is flawed because, as you have explained, the candidate lists can vary between Regions (NA, PP, etc.) and even between Area Codes within the same Region (e.g., NA-001, NA-002, etc.). I suspect your method for creating the list of candidates on each ballot must be done manually. If that is the case, I have a recommendation. Earlier you mentioned that separate lists were maintained for each region (NA, PP, etc.). Consider converting each of those lists to an official Excel table (click in the list and hit Ctrl-t) and then give each of the tables a meaningful name. In the example I have created, I used names of tblNA, tblPP, etc. Use those tables for your vote tabulations...there is no need to combine the tables just yet, and maintaining the votes in each table might prove to be easier. In my example, I have a formula for each of these tables to flag if any vote tallies are missing (then the "Blanks" cell shows a non-zero number and it turns red).

After all votes have been tallied (and the "Blanks" checks are all green), then the summary table can be completed. I have a simple Power Query script that combines all of the individual vote tabulation tables into a single table similar to your original one. This table occupies columns Q:U, but it uses no in-cell formulas. The instructions to combine the tables and perform the [% of Candidate Votes] computation are in the M code:
Power Query:
let
    NA = Excel.CurrentWorkbook(){[Name="tblNA"]}[Content],
    PP = Excel.CurrentWorkbook(){[Name="tblPP"]}[Content],
    PS = Excel.CurrentWorkbook(){[Name="tblPS"]}[Content],
    PB = Excel.CurrentWorkbook(){[Name="tblPB"]}[Content],
    KP = Excel.CurrentWorkbook(){[Name="tblKP"]}[Content],
    tbl1 = NA & PP & PS & PB & KP,
    #"Changed Type" = Table.TransformColumnTypes(tbl1,{{"Votes", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Region-Area Code"}, {{"Region-Area Total Votes", each List.Sum([Votes]), type number}, {"All", each _, type table [#"Region-Area Code"=text, Candidate Name=text, Party Name=text, Votes=number]}}),
    #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"Candidate Name", "Party Name", "Votes"}, {"Candidate Name", "Party Name", "Votes"}),
    #"Added Custom" = Table.AddColumn(#"Expanded All", "% of Candidate Votes", each [Votes] / [#"Region-Area Total Votes"] ),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Region-Area Total Votes"})
in
    #"Removed Columns"
The table produced by this Power Query script is another official Excel table that is loaded onto the summary sheet in cell Q1 (upper left). There are mostly advantages with this "table" being an official table, because formulas can use structured references, which dynamically adjust to the length of the table. The biggest disadvantage is that Excel does not allow for structured references in formulas for Conditional Formatting. I investigated several options. The two most promising involved either wrapping all of the structured references with INDIRECT functions or using named ranges. I am generally not fond of using volatile functions (like INDIRECT), and while it worked okay in my tests, performance may be a problem as the table grows. Therefore, I adopted Named Ranges, where the table columns for [Region-Area Code] and [Votes] were named aryRACodes and aryVotes, respectively, using a dynamic range formula based on INDEX and employing a helper cell that identifies the bottom row of the table (cell AA2). Using these named ranges, conditional formatting is applied to the table to highlight the winner and runner-up. Another conditional formatting formula inserts a black cell border between different groups of Region-Area Codes.

Another Power Query script creates a simple one-column table (column W) showing the unique Region-Area Codes that are found in the combined vote tabulation table. This single column table can be used to confirm that all of them are present in the main summary table (columns A:O). I have inserted a formula to make this check in Y1:Y2 (if a Region-Area code is missing, a "Problem" will be flagged). Similarly, the blank votes checks performed on each of the region vote tally tables are examined in Z1:Z2 to report if any blanks exist. These cells (Y1:Z2) provide a convenient check before the combined vote tabulation table is refreshed. This table is not dynamic...it needs to be refreshed (I recommend using Date > Refresh All to refresh both PQ queries).

I rearranged some columns in the main summary table so that everything manually entered is on the left and everything delivered by formulas on the right. The formulas have been revised to use structured references.
Mrexcel_20220924_mwvirk.xlsx
ABCDEFGHIJKLMNO
1NA # (2018)ProvinceNA # (2013)Seat NameRegistered VotersRejected VotesValid Cast VotesTotal Cast Votes% Of Total Registered VotesWinner's NameWinner PartyRunner up NameRunner up PartyPrevious Winner's Name In 2018Previous Party Name In 2018
2NA-001Kingdom ValleyBlue Area 1Blue Area 1A318150500700075002.357%Name 0004Party ADName 0002Party AB
3NA-002Kingdom ValleyBlue Area 2Blue Area 2B318150500430048001.509%Name 0001Party AAName 0002Party AB
4NA-003Kingdom ValleyBlue Area 3Blue Area 3C31815050011000115003.615%Name 0006Party AFName 0003Party AC
5PB-001Province-2Name-004Area-00440004000 Name IParty AFName IParty AF
6PB-002Province-2Name-005Area-00520002000 Name FParty ADName FParty AD
7PP-001Province-3Name-006Area-00630003000 Name FParty ADName FParty AD
8PP-002Province-4Name-007Area-00740004000 Name FParty ADName FParty AD
9PP-003318150500370042001.320%Name MParty ADName 0009Party AI
10PS-00150305030 Name JParty AGName HIndependent
11PS-002318150500900095002.986%Name JParty AGName KParty AH
12KP-001318150500300235021.101%Name 0007Party AGName 0005Party AE
13KP-002318150500200125010.786%Name 0008Party AHName 0009Party AI
14KP-003318150500390044001.383%Name 0007Party AGName 0006Party AF
Election 2022_v4
Cell Formulas
RangeFormula
G2:G14G2=SUMIF(tblAll[Region-Area Code],$A2,tblAll[Votes])
H2:H14H2=SUM($F2:$G2)
I2:I14I2=IF($E2=0,"",$H2/$E2)
J2:J14J2=IFERROR(INDEX(tblAll[Candidate Name],AGGREGATE(15,6,(ROW(tblAll)-ROW(tblAll[#Headers]))/((tblAll[Region-Area Code]=$A2)*(tblAll[Votes]=(LARGE((tblAll[Votes])*(tblAll[Region-Area Code]=$A2),1)))),1)),"")
K2:K14K2=IFERROR(INDEX(tblAll[Party Name],AGGREGATE(15,6,(ROW(tblAll)-ROW(tblAll[#Headers]))/((tblAll[Region-Area Code]=$A2)*(tblAll[Votes]=(LARGE((tblAll[Votes])*(tblAll[Region-Area Code]=$A2),1)))),1)),"")
L2:L14L2=IFERROR(INDEX(tblAll[Candidate Name],AGGREGATE(15,6,(ROW(tblAll)-ROW(tblAll[#Headers]))/((tblAll[Region-Area Code]=$A2)*(tblAll[Votes]=(LARGE((tblAll[Votes])*(tblAll[Region-Area Code]=$A2),2)))),1)),"")
M2:M14M2=IFERROR(INDEX(tblAll[Party Name],AGGREGATE(15,6,(ROW(tblAll)-ROW(tblAll[#Headers]))/((tblAll[Region-Area Code]=$A2)*(tblAll[Votes]=(LARGE((tblAll[Votes])*(tblAll[Region-Area Code]=$A2),2)))),1)),"")
Named Ranges
NameRefers ToCells
'Election 2022_v4'!aryRACodes='Election 2022_v4'!$Q$2:INDEX('Election 2022_v4'!$Q:$Q,'Election 2022_v4'!$AA$2)J2:M14, G2:G14
'Election 2022_v4'!aryVotes='Election 2022_v4'!$T$2:INDEX('Election 2022_v4'!$T:$T,'Election 2022_v4'!$AA$2)J2:M14, G2:G14
'Election 2022_v4'!ExternalData_1='Election 2022_v4'!$Q$1:$U$45J2:M14


Here is a portion of the combined vote tabulation table and the helper cells:
Mrexcel_20220924_mwvirk.xlsx
QRSTUVWXYZAA
1Region-Area CodeCandidate NameParty NameVotes% of Candidate VotesRegion-Area CodeMismatched RA CodesBlank Vote TalliesKeep: helper bottom row
2NA-001Name 0001Party AA100014.29%KP-001OkayOkay45
3NA-001Name 0002Party AB200028.57%KP-002
4NA-001Name 0003Party AC100014.29%KP-003
5NA-001Name 0004Party AD300042.86%NA-001
6NA-002Name 0001Party AA120027.91%NA-002
7NA-002Name 0002Party AB110025.58%NA-003
8NA-002Name 0003Party AC100023.26%PB-001
9NA-002Name 0004Party AD100023.26%PB-002
10NA-003Name 0005Party AE10009.09%PP-001
11NA-003Name 0006Party AF500045.45%PP-002
12NA-003Name 0003Party AC400036.36%PP-003
13NA-003Name 0004Party AD10009.09%PS-001
14PP-001Name FParty AD100033.33%PS-002
15PP-001Name GParty AE100033.33%
16PP-001Name HIndependent100033.33%
17PP-002Name FParty AD100025.00%
Election 2022_v4
Cell Formulas
RangeFormula
Y2Y2=IF(SUM(--NOT(ISNUMBER(MATCH(tblRACodes[Region-Area Code],A2:A20,0))))>0,"Problem","Okay")
Z2Z2=IF(SUM('Election 2022_v4_ballots'!A2:X2)>0,"Problem","Okay")
AA2AA2=ROWS(tblAll[#Data])+ROW(tblAll[#Headers])
Named Ranges
NameRefers ToCells
'Election 2022_v4'!aryRACodes='Election 2022_v4'!$Q$2:INDEX('Election 2022_v4'!$Q:$Q,'Election 2022_v4'!$AA$2)AA2
'Election 2022_v4'!aryVotes='Election 2022_v4'!$T$2:INDEX('Election 2022_v4'!$T:$T,'Election 2022_v4'!$AA$2)AA2
'Election 2022_v4'!ExternalData_1='Election 2022_v4'!$Q$1:$U$45AA2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
P2:U45Expression=$Q3<>$Q2textNO
T2:U45Expression=AGGREGATE(14,6,aryVotes/(aryRACodes=$Q2),1)=$T2textNO
T2:U45Expression=AGGREGATE(14,6,aryVotes/(aryRACodes=$Q2),2)=$T2textNO

And an example of the individual regional vote tally tables:
Mrexcel_20220924_mwvirk.xlsx
ABCDEFGHI
1
2Blanks0Blanks0
3
4Region-Area CodeCandidate NameParty NameVotesRegion-Area CodeCandidate NameParty NameVotes
5NA-001Name 0001Party AA1000PP-001Name FParty AD1000
6NA-001Name 0002Party AB2000PP-001Name GParty AE1000
7NA-001Name 0003Party AC1000PP-001Name HIndependent1000
8NA-001Name 0004Party AD3000PP-002Name FParty AD1000
9NA-002Name 0001Party AA1200PP-002Name GParty AE1000
10NA-002Name 0002Party AB1100PP-002Name HIndependent1000
11NA-002Name 0003Party AC1000PP-002Name MParty AD1000
12NA-002Name 0004Party AD1000PP-003Name 0008Party AH1000
13NA-003Name 0005Party AE1000PP-003Name 0009Party AI1300
14NA-003Name 0006Party AF5000PP-003Name MParty AD1400
15NA-003Name 0003Party AC4000
16NA-003Name 0004Party AD1000
17
Election 2022_v4_ballots
Cell Formulas
RangeFormula
D2D2=COUNTIF(tblNA[Votes],"")
I2I2=COUNTIF(tblPP[Votes],"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
D2,I2,N2,S2,X2Expression=D$2=0textNO
D2,I2,N2,S2,X2Expression=D$2<>0textNO

Setting this up may be complicated, so the working file I used is available here (and it includes past worksheet iterations/formulas). I would recommend looking at the last two worksheets from which the above content was taken.
 
Upvote 0
Solution
Thank you so much and appreciate your kind support.
This is working perfectly now and I have updated my entire sheet.

Regards,
MWVirk
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top