Given a story problem:
A string of Christmas lights of 150 lights total (Could Be Infinite)
Two possible values for the lights 0=Off or 1=On
If the lights are initially all 0:
Person1 turns all the lights to 1:
Person2 turns lights 2,4,6,8,...150 to 0:
Person3 turns lights 3,6,9,12...150 to 1:
Person4 turns lights 4,8,12,16...150 to 0:
Continuing on for 150 people.
How would I express this in an excel formula?
This needs an iterative approach. Go to File | Options | Formulas, set Workbook calculation to Manual, tick Enable Iterative Calculation and set Maximum iterations to 1.
Set the light numbers 1-150 in C2-C151 using fill series.
Put the following formula in B2 to iterate through the person numbers:-
=IF(A2,0,B2+1)
Put the following formula in D2 to find if the light in C2 will be switched on or off (the odd guys always switch ON, even guys switch OFF but only for lights which are an exact multiple of their person number):-
=IF(A$2,FALSE,IF(MOD(C2,B$2)=0,ISODD(B$2),D2))
Copy the formula down from D3 to D151.
I've also put a formula to display a text string "ON" or "OFF" in E2 but this is optional:-
=IF(D2,"ON","OFF")
To initialise it (there might be a neater way of doing this), type a '1' in A2.
There should be a 'Calculate' button at the bottom of the screen. Pressing this once should set all the lights 'OFF'
Type a '0' in A2. Now each time you press 'Calculate' it will simulate the action of the person whose number is displayed in B2.
Here's how it would look after Person 3 has had a go:-
If you want to see how it would look after all 150 have had a go, go back in to File | Options | Formula and set Maximum Iterations to 150.
Reset it as before and calculate.
Now it looks like this:-
The lights alternate - was this what you expected? For all the even lights, the most recent action was performed by an even guy so it's off, and vice-versa.
Or maybe you were thinking of the problem outlined in Matt Parker's book Things to Make and Do in the 4th Dimension. Here a succession of guards can lock and unlock cell doors with the same constraints except that they always turn a 0 (locked) into a 1 (unlocked) and a 1 into a 0 and it turns out that the ones that stay open are the ones with square numbers 1,4,9,16 ...
In this case the formula in column D would be
=IF(A$2,FALSE,IF(MOD(C2,B$2)=0,NOT(D2),D2))
and it would look like this:-
Related
I am creating a formula to try yo find the total amount in pounds that is in in-transit. The current lead time is 5 days. But I have placed a manual override where we could change the lead time to 10 days for example. How do I get it to change outcome to be similar to the 2nd picture below.
the equation in the first white cell is the following
=SUM(OFFSET(B1,0,0,5))
where 5 is the default lead time, but I would like to have that change depending on whether there is a value in the lead-times override (Final Column)
This equation is dragged down to the remaining white cells in this table so that the last white cell is
=SUM(OFFSET(B12,0,0,5))
Current Results
This is what I want it to look like
Desired results
Sorry if I am unclear in my question since, it is a bit hard to explain in writing.
Just check if the value exists and use it. If not, fall back to 5.
=SUM(OFFSET(B1,0,0,IF(NOT(ISBLANK($C$9)), $C$9, 5)))
Don't forget to make the override cell static (with the dollar signs) or they will shift when dragging your formula.
So this is the simplified question I broke down from a former question I had here: Excel help on combination of Index - match and sumifs? .
For this one, I have Table1 (the black-gray one) with two or more columns for adjustments for various order numbers. See this image below:
What I want to achieve is to have total adjustments for those order numbers that contain the numbers in Total Adjustment column in the blue table, each of which will depend on the cell beside it.
Example: Order number 17051 has two products: 17051A (Apple) and 17051B (Orange).
Now what I want to achieve in cell C10 is the sum of adjustment for both 17051A and 17051B, which will be: Apple Adjustment (5000) + Orange Adjustment (4500) = 9500.
The formula I used below (and in the image) kept giving me error messages, and this happens even before I add the adjustment for Orange.
=SUMIF(Text(LEFT(Table1[Order Number],5),"00000"),text(B10,"00000"),Table1[Apple Adjustment])
I have spent the whole day looking for a solution for this and didn’t even come close to find any. Any suggestion is appreciated.
Assuming your headers always have the text "adjustment" in them, you could use:
=SUMPRODUCT((LEFT($B$4:$B$7,5)=B10&"")*(RIGHT($C$3:$F$3,10)="adjustment")*$C$4:$F$7)
In C10 you could add two sumproducts. This assumes that products are always 5 numbers long at the start. If not swop the 5 to use the length of the product reference part you are matching on.
=SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$D$4:$D$7)+SUMPRODUCT(--(1*LEFT($B$4:$B$7,5)=$B10),$F$4:$F$7)
Which with table syntax is:
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],5)=$B10),Table1[Orange Adjustment])
Using LEN
=SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Apple Adjustment])+SUMPRODUCT(--(1*LEFT(Table1[Order Number],LEN($B10))=$B10),Table1[Orange Adjustment])
I am multiplying by 1 to ensure Left, 5 becomes numeric.
Listed below is the formula where I would like to add 2 more conditions. All tempts have displayed a name error. I have tried IFS, IF AND functions also.
My goal is to display Low if <1.99, MED if 2 - 2.99 or HIGH if 3.
=IF(SUBTOTAL(101,[IM])<1.99,"Low","F")
nested IF:
=IF(SUBTOTAL(101,[IM])<1.99,"Low",IF(SUBTOTAL(101,[IM])<2.99,"Med","High")
Your logic has holes that are not covered by your rules. I believe it should be closer to Low if <2, MED if 2 - 2.99 or HIGH if >=3. It is very possible that you will get 3 or more decimal places on an average.
=LOOKUP(SUBTOTAL(101, [IM]), {1E-99,2,3}, {"Low","Med","High"})
FWIW, the same can be accomplished by putting =SUBTOTAL(101, [IM]) in a cell and applying a custom number format of,
[Red][<2]Low;[Blue][>=3]\Hi\g\h;\M\e\d
I've added red font for Low and blue font for High. The added value here is that despite displaying Low, Med or High, the cell contains the underlying average value that can be used in calculations.
=CHOOSE(MAX(1,MIN(3, INT(SUBTOTAL(101, [IM])))), "Low", "Med", "High")
Assuming your data is in column A, paste this in column B and drag it down:
=IF(SUBTOTAL(101,[IM])<1.99,"LOW",IF(AND(SUBTOTAL(101,[IM])>2,SUBTOTAL(101,[IM])<2.99),"MED","HIGH"))
Good afternoon,
I am looking for an Excel/GOOGLE Sheet =SUM(IF()) statement formula that will help to know if I have made or lost money in any given month. To save time when inputting the information, I would like to have once cell in the TOTAL row calculate what is a positive and negative number depending on the PAYMENT TYPE used, and printout the remainder.
This is also maintain inventory for when new items are added to my life during this one month period, because I'm just weird like that.
(See Google Sheet Link for example) ie Expense Report
ie. My expenses are arranged by in a column PAYMENT TYPE: CC (for credit card, negative), CASH (negative), GC (for gift card, not added), or DEPOSIT (for income, positive).
The "added negative/positive" is how the balances should look: red for money spent (CC, CASH), gray for no expense (GC), green for money earned (DEPOSIT).
The =sum(if()) formula would then be able to easily calculate the end result, either in red (money lost) or green (money earned).
If there is another formula outside of =sum(IF()) that would do this job, I am very interested in seeing how it would be applied, so I can learn it.
Thank you for your responses, in advance.
-ECP03
Unfortunately, my current network blocks Google Docs so I can't view your example doc. From what I've gathered, you have a a couple information columns (expense, amount, etc) and then one column that includes the payment type. Here are 2 ways you could do this:
Assumption: you have NAME (Range A1:A5), EXPENSE (Range B1:B5), and PAYMENT_TYPE (Range C1:C5) as your 3 columns with 4 total transactions. Header is the first row (A1:C1). This assumes you will never have more than 1000 transactions to keep track of; just modify 1000 to whatever new max you require.
1) This solution gives you your sum. It does not tell you the positive and negative contributions of the positives and negatives. For that see Solution 2.
Set the cell that you want your net income to be to:
=SUMIF(C1:C1000,"DEPOSIT",B1:B1000)-SUMIF(C1:C1000,"CC",B1:B1000)-SUMIF(C1:C1000,"CASH",B1:B1000)
2) This is the solution that shows both positive and negative contributions.
Set aside 3 cells (say E1, E2, and E3). Set E1 to:
=SUMIF(C1:C1000,"CC",B1:B1000)+SUMIF(C1:C1000,"CASH",B1:B1000)
This is your 'negatives' cell. Set E2 to:
=SUMIF(C1:C1000,"DEPOSIT",B1:B1000)
Set E3 to:
=E2-E1
Then all you have to do is use conditional formatting (if you don't know how to do this just let me know or Google it) to set cell E3 to be green if the amount in it is > 0, red if it is < 0, and gray if it is = 0.
Thank you, Judu Le.
That formula does the trick.
I did use your first answer.
ie. =SUMIF(C1:C1000, "DEPOSIT", B1:B1000) - (SUMIF(C1:C1000, "CC", B1:B1000)+SUMIF(C1:C1000,"CASH",B1:B1000))
The end result did not add or subtract the GC balance, which is what I wanted.
This worked perfectly. Thank you for your timely feedback.
-ECP03
Could someone help me with an excel formula to run a test 1000 times where there are only two possibilities of the event to occur out of 40 outcomes. Is it possible in excel?
For example: I have 40 numbered stones in a bunch from 1 to 40. How many times I randomly pick stone no.1 or 2 when I try this 1000 times?
Is it possible to execute this in excel and get a detailed answer in %?
Here's one way:
Put this formula in A1 and copy down to A1000,
it will act as the random event of choosing a stone:
=RANDBETWEEN(1,40)
In another cell, put this formula to get the count of 1's and 2's:
=SUM(COUNTIF(A1:A1000,{1,2}))
To get the percent, well, I'm sure you can figure that out.
Every time you click F9 the random numbers in column A will recalculate.
Of course, Excel doesn't generate truly random numbers.
This particular statistical problem has been well studied by mathematicians, so you don't have to simulate but can use a well known result. Or, if you must simulate (say, for homework), this can provide a way to test it.
When you have an event E that can happen 1/20=0.05 of the time, and you want to know a probability that the event E happens K (K=0,1,2,3,...,999,1000) times in N=1000 tests, the answer to that is the Binomial Distribution B(n=1000,p=0.05).
In Excel, this Binomial Distribution is available with BINOMDIST().
Example
BINOMDIST(49, 1000, 0.05, FALSE)
gives the probability of seeing K=49 events out of N=1000 tests when the event has prob p=0.05.
FALSE is for one particular outcome of the 1000 tests, i.e. K=49.
TRUE would give the cumulative probability of less than or equal, i.e. summing up the probabilities for K=0,1,2,3,...,49 events.
In cell A1 enter =RANDBETWEEN(1,40) then copy it down to B1000
In cell C1 enter =IF(OR(AND(A4=1,B4=2),AND(A4=2,B4=1)),1,0)
in cell D1 enter =SUM(C:C)/1000
Pressing F9 will recalculate