I basically have three tables that I want to test through an IF/ else IF formula in Excel. The first table corresponds to whether I would take a bet given a set of parameters (in short, this is a n row x 1 column table filled with 1s and 0s). The second table is whether I would win the bet (this is also nx1 and filled with 1s and 0s). The third column is the profit I would make if I did take the bet AND if I won.
So far the pseudo-code I have is:
if (would bet=1) AND (would win=1), are...
TRUE: display profits
FALSE: if (would bet=1) and (would win = 0) are...
TRUE: -1 (for losing $1 betting)
FALSE: 0 (for not betting)
I have my tables set up as follows:
Profits table: column A
Would bet table: Column B
Would win table: Column C
so in cell D1, I entered:
=IF(AND(B1=1, C1=1), A1, IF(AND(B1=1, C1=0), -1, 0))
but for some reason, I'm not getting any -1's though there are supposed to be some.
Can anyone help?
Thanks.
I think you can simplify your logic a bit to the following pseudo code:
IF (would bet)
IF (would win)
DISPLAY PROFITS
ELSE
DISPLAY -1 // loser!
ELSE
DISPLAY 0 // didn't play
With that simplified logic, I think you can go with this as your formula:
=IF(B1=1, IF(C1=1, A1, -1), 0)
Where B1 = would bet, C1 = would win, A1 = profits
As a small aside/contribution, this is a fairly short formula, but I often split complex IFs in several columns to do the debugging easier , or, for really complex (or maybe overcomplicated :)) decisions I create a custom formula and code the logic as in your pseudocode pretty much. that has a performance penalty in big tables and requires saving it as a macro enabled xlsm which requires users to enable the content, but it improves auditability massively, reduces the risk of error and let to comment the code for the future. I would recommend (if not yet familiar) that you give it a go to have another tool in your belt. You can google around on how to create a custom formula)
Cheers
Related
I have column I as a calulation column and this is what I currently wrote.
and this gives me nothing.
=IF(B2<>""&D2<>"",B2*D2,IF(B2<>""&D2=""&C2<>"",B2*C2,IF(A2<>""&C2<>""&AND(B2&D2=""),A2*C2,IF(A2<>""&C2=""&D2<>""&B2="",A2*D2,A2*C2))))
The logic is if B2 and D2 are not null multiply b2*d2
if B2 is not null and D2 null then b2*c2
If B2 is null and D2 is not null then a2*d2
else a2*c2
Is any ways to make this code work?
Thank you
Alternative ways or rewriting your formula:
=IF(AND(B2<>"",D2<>""),B2*D2,IF(D2="",IF(B2<>"",B2*C2,A2*C2),IF(D2<>"",A2*D2,A2*C2)))
=IF(AND(B2<>"",D2<>""),B2*D2,IF(AND(B2="",D2=""),A2*C2,IF(D2="",B2*C2,A2*D2)))
They will make negligible difference in performance and what not. BruceWayne's answer is probably more readable in terms of following your logic and therefore easier to maintain or understand in the future. The above answers should provide the same results but are a few characters shorter in length.
And as a wacky alternative for thinking potentially outside the box:
=CHOOSE(SUM((B2<>"")*2+(D2<>""))+1,A2*C2,A2*D2,B2*C2,B2*D2)
Expanding (not just my waist size)
I had time on my hands so I was fooling around with the concept of TRUE and FALSE being equal to 1 and 0 when sent through a math operation. When I started looking at the options this reminded me of how a binary number works. Not that I have bgiven it too much thought, but I think it works because the options for each cell are binary or TRUE/FALSE. Since every possible combination was covered with a unique out come, I just had to come up with a formula that would produce unique results. In this case I just took the converting a a binary number approach. The key is TRUE = 1 after a math operation and FALSE = 0. Now going the other direction is not quite the same but as Jeeped once put it, 0 is FALSE and everything else is TRUE. so 3, -3, and 3.14 are all treated as TRUE if using the numerical values as the outcome of a logic check.
=IF(3.14,"THIS NUMBER IS TRUE","ONLY 0 IS FALSE")
So less side tracking and back on point (not sure how much I need to expand to!).
Looking at the table above, you will note in the yellow area, all possible combination for BLANK and NOT BLANK are listed. If you then assign a value to the column the same way binary numbers are (note row A) you can then start generating all the possible numbers
I started by generating the list I needed in E2:E5 for numbers that CHOOSE could work with. I assumed 0 would beat up CHOOSE and cause it to fail. I knew that FALSE+FALSE=0 and I also knew that TRUE+TRUE=2 and that both TRUE+FALSE=1 and FALSE+TRUE=1. I needed a way to distinguish the later two and I knew I needed a total of 4 results. That is when binary counting/conversion whatever you want to call it kicked in. I placed the following formula in D2 and copied down
=SUM((A2<>"")*2+(B2<>""))
Note the brackets around the logic check and
that the logic checks are sent through a math
operation before being summed.
technically speacking it is really:
=SUM((A2<>"")*2+(B2<>"")*1)
however the *1 is not needed
once I had that list generate, it was a simple +1 added to it to get into the 1 to 4 range seen in E2:E5.
Now that I had a way of generating the index number the only thing left to do was to match up the required results/formula with the right combination.
=CHOOSE(SUM((A2<>"")*2+(B2<>""))+1,"A","B","C","D")
Well I felt like I was beating a dead horse there for a bit, so if I over explained, my apologies. If there is something still missing ask for more explination.
UPDATE TID BIT
IF there were more columns to check it may be possible to adjust the choose formula by simply adding the next binary value to the column and making sure there is an appropriate number of results in the choose list. There should be 2^(# of columns to check) options
=CHOOSE(SUM((A2<>"")*4+(A2<>"")*2+(B2<>""))+1,"A","B","C","D","E","F","G","H")
Which kind of beats multiple nested IFs for brevity, but I think I finds the nested IFs easier to understand.
You should be using AND():
=IF(AND(B2<>"",D2<>""),B2*D2,IF(AND(B2<>"",D2=""),B2*C2,IF(AND(B2="",D2<>""),A2*D2,A2*C2)))
You seem to be mixing operators from other programming languages:
In Excel:
AND : binary operator : AND(TRUE, FALSE) => FALSE
& : concatenation : "Hello " & "World" => "Hello World"
I'm trying to design a second page that shows % results of my data on page 1.
For example, Column F & G allow manual entry of numbers 1-4 which are based off data the user types in at another location.
This is being used for trade tracking in investments so there will be quite a few numbers but the end result will be a row will show a specific stock, it's subsequent data, whether it made or lost money, etc.
What I want to do in page 2 is using the numbers 1-4 which were typed in at columns F & G, translate that into an edge on page 2.
For example, if there were 50 columns of data typed out for trades executed, I could take the number of winning trades of a certain setup (say number 3) and divide that by the total trades of 50 to come out with a win % for that setup.
However, I have no clue to how to translate that forumla into a filter formula so that on page 2 I could see that of the numbers 1-4 (4 different setups) I could easily see the highest and lowest win % to determine the best setup to use.
I'm not the best in excel but I understand enough to code most of that, I simply have no idea how to take that end formula and add a filter to it so that it only uses partial results. I've got 4 other formulas I want to use on page 2 as well to help build something that could really benefit myself, but if someone could just show me how to filter data into a formula, I think I could take it form there.
Thanks for the help
Ben
You can also do something like this with array formulas
=MAX(IF(Sheet1!$F$2:$F$50=$A2,$E$2:$E$50))
(Press Ctrl+Shift+Enter [CSE], instead of just Enter when entering Array Formulas)
Also, take a look a the SUMPRODUCT function. It comes in very handy for filtering data. Here are some helpful links...
https://www.get-digital-help.com/2017/12/07/sumproduct-multiple-criteria/
https://www.get-digital-help.com/2017/12/08/sumproduct-and-if-function/
https://www.get-digital-help.com/2010/09/01/extract-a-unique-distinct-list-by-matching-items-that-meet-a-criterion-in-excel/
I am looking for a method to match two excel tables.
I basically have two Systems, where the values do not exactly match only some IDs. The values in system 2 are usually 10-20% different from system 1.
Here is how the sheet looks like:
I tried to use vlookup on the IDs and then going hand-by-hand through the values if they match, by using the filter with the ID. However, this takes extremely long and is very cumbersome.
Any recommendation how to match these two tables, much more easily?
I really appreciate your replies!
If you look at a formula for G3 you would be involving D3:E3 and A:B (where A10:B10 are the matching values).
When someone states that they are looking for a percentage, it is helpful to know "a percentage of what...?". You receive a different result if the calculation is ABS(12 - 15)/15 instead of ABS(12 - 15)/12. One may within tolerance and the other may not.
In any event, the formula for G3 would be something like,
=ABS(E3-VLOOKUP(D3,A:B, 2, FALSE))/E3
... or,
=ABS(E3-VLOOKUP(D3,A:B, 2, FALSE))/VLOOKUP(D3,A:B, 2, FALSE)
That produces a result of 0.25% or 0.20% depending on how you calculate the percentage. You could wrap that in an IF statement for a YES/NO text result or use a custom number format like [Color3][>0.2]\NO;;[Color10]\Y\E\S;# which will show a red NO for values greater than 20% and a green YES for values between 0 and 20%. Negative values do not have to be accounted for as the ABS removes them from consideration.
I've only reproduced a minimum of your sample data for demonstration purposes but perhaps you can get an idea on how to proceed from that.
I am thinking this is gonna be a simpler answer than I'm making it, but here goes nothing. I have a project I am working on using Excel and Python, where I am going to calculate the results for a season of NASCAR using the different points systems. I had tried doing this only using Python, but figured doing it in Excel first is better. The thing is, I have all the results for all 36 races inputted in Excel, with formatting for drivers who lead a lap, drivers who lead the most laps, and drivers not elligible for points.
How I have the formatting is as follows:
Inelligible driver's names are in red text.
Driver(s) who lead a lap are in bold text.
Driver(s) who lead the most laps are in bold text and bold border.
Driver(s) who had penalties have a red background.
Is there a way I could assign values based on these formatting conditions?
As for the penalties, those I could calculate separately if needed.
Please let me know whatever you may suggest.
Each column contains the results for a single race, and since there are always 43 drivers, the block of cells contains 43 rows (plus a heading row with each race name).
An option I'm thinking of is, to have the results for each race on Sheet1, then on Sheet2 have a list of all valid driver names, then copy and paste it twice, one for each option (2 bonus points, 1 bonus point, and no bonus points), and name each list. Also, I will have names for each driver, as well as names for each position. Then, when calculating the points after a race, use an if-then-else formula similar to the following:
IF A2 = driver_most_led [Driver_Name = Driver_Name + Position_Points + Most_Led_Bonus], ELSE IF A2 = driver_lead [Driver_Name = Driver_Name + Position_Points + Lead_Bonus], ELSE [Driver_Name = Driver_Name + Position_Points])
I know it's a long example, but not sure if this is legit or not.
My apologies if this has already been answered in some form; it’s difficult to come up with the correct wording to do a proper search.
I have been charged with creating some basic reporting for my team and I need to create an “if-then” formula. Essentially, if Column A contains the word “Open Rate,” I want the formula to grab the associated percentage from column B (16.49%) and make an average of all the open rates on another sheet. (16.49% + 14.98% + 14.48% / 3 = 15.31%)
I would simply add all of them but the data set is ridiculously large and always growing. Also, the numbers of rows between data sets are not equal and thus a nice pattern is out of the question.
excel uses a vb type syntax
=IF(A2<>"open rate",A2,AVERAGE(Sheet2!A:A))
the above formula says if a2 is not equal to open rate, then return a2, else return the average of column A in sheet 2
Please try:
=AVERAGEIF(Sheet1!A:A,"=Open Rate",Sheet1!B:B)
with your first sheet name adjusted to suit, if necessary.
Edit re supplementary
Google Doc does not at the moment have a function =AVERAGEIF, however it does have the building blocks for it. Average (as in arithmetic mean) may be calculated as the sum of the values in a dataset divided by the count of all the individual items in the dataset:
=sumIF(Sheet1!A:A;"=Open Rate";Sheet1!B:B)/countIF(Sheet1!A:A;"=Open Rate")
Google Doc does have the =AVERAGE function and this may be more suitable than the above.