0

我正在尝试使用 excel 公式来确定每个by的比例 ( pDistance) 。例如,如果 (total)是 50,并且是 10,则总距离 ( ) 的比例将为 0.2,最后一个应该始终为 1。我使用的公式 ( ) 大部分都有效,除了我有一些值那是-10。 DistancePositionSiteDistancePositionpDistancepDistanceSite=IF(B3<B2, 1, (B2/C2))Position

在这些情况下PositionSite在计算pDistance. 这可以用一个公式来完成,即计算pDistance并在必要时加 10?还是最好先制作一个虚拟列?如果创建一个虚拟列是要走的路,那么在满足条件之前如何使用公式做某事(例如Position,添加 10 直到达到 0 或 new Site)?

需要条件语句的if语句的excel 2013屏幕截图

4

1 回答 1

1

From the sample data, I understand that for any Site which has a value of -10 somewhere in column B, then the calculation of (B / C) needs to be ((B + 10) / C). (Although cell D11 doesn't follow this, I'm assuming it's just a typo :) )

The formula below would work in this case:

D2 = (SUMPRODUCT(($A$2:$A$22=$A2)*($B$2:$B$22=-10))*10 + B2) / C2

This formula works as follows:

  1. SUMPRODUCT(($A$2:$A$22=$A2)*($B$2:$B$22=-10))

    --> This will return the total number of rows which contain the value of A2 in column A and a -10 in column B :

    • ($A$2:$A$22=$A2) looks at all values in the cells between A2 & A22, and finds which ones match A2. That is, it finds which rows that have the same Site number as the row where the formula is entered
    • ($B$2:$B$22=-10) looks at all values in the cells between B2 & B22, and finds which ones equal -10. That is, it finds all rows that have a Distance value of -10.
    • The SUMPRODUCT finds the overlap of these. So, it counts how many rows have both the right Site number and a distance value of -10.
  2. This value is than multiplied by 10. If there were no -10 values paired with the site, then it is 0 * 10 = 0. If there was one pair, it will be 1 * 10 = 10.

  3. That result is then added to B2, and then divided by C2.

Note: this formula assumes that there will only be a maximum of one -10 value for a particular site. If there is more than one, then the SUMPRODUCT will return the total number of matches, and the calculation will be wrong (but the formula can be updated to correct this).

Also note that the formula refers to the ranges $A$2:$A$22 and $B$2:$B$22. These ranges must match the first and last numerical entry in your data (and not include any text - this will break the SUMPRODUCT formula). The simplest way to handle this (if you don't want to have to update the formula when adding values at the end of data set) is to set up a defined range name and refer to that in the formula.

To apply the formula, just paste it into D2, and copy/drag the formula down into the cells below.

As a conclusion, I can recommend that you create a "dummy" / "helper" column to store the (SUMPRODUCT * 10) + B2 results, and use this as the input for the division calculation. This will help to visualize and check the data that is being used for the calculation. It can be hidden until you want to check the values or change the formula in case the requirements change in the future.

于 2013-10-17T15:22:30.350 回答