Excel AKICOLJ
May. 12th, 2012 09:44 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
I want a function that returns a value equal to (x six-sided dice minus y six-sided dice) but which returns the answer '0' if the formula would otherwise result in a negative answer.
Or, to put it in role-playing terms, something like "4d6-3d6, but show any negatives as zero".
Doing the 4d6-3d6 bit is easy:
=(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))-(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))
I had thought of then putting this inside an IF function, so that if the formula above was >=0, it showed the formula above, but if it was <0, it showed 0:
=IF((RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))-(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)),(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))-(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)),0)
Unfortunately, that second function doesn't work. The reason it doesn't work is that it is recalculating the 4d6-3d6 part. That means that if the original 4d6-3d6 is positive, the formula doesn't show that positive number. Instead it rolls 4d6-3d6 again and shows the answer to that.
Any ideas?
Or, to put it in role-playing terms, something like "4d6-3d6, but show any negatives as zero".
Doing the 4d6-3d6 bit is easy:
=(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))-(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))
I had thought of then putting this inside an IF function, so that if the formula above was >=0, it showed the formula above, but if it was <0, it showed 0:
=IF((RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))-(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)),(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6))-(RANDBETWEEN(1,6)+RANDBETWEEN(1,6)+RANDBETWEEN(1,6)),0)
Unfortunately, that second function doesn't work. The reason it doesn't work is that it is recalculating the 4d6-3d6 part. That means that if the original 4d6-3d6 is positive, the formula doesn't show that positive number. Instead it rolls 4d6-3d6 again and shows the answer to that.
Any ideas?