SPS中计算值公式函数简介
Conditional formulas
You can use the following formulas to test the condition of a statement and return a Yes or No value, to test an alternate value such as OK or Not OK, or to return a blank or dash to represent a null value.
Determine whether a number is greater than or less than another number
Use the IF function to perform this comparison.
Column1 |
Column2 |
Formula |
Description (possible result) |
15000 |
9000 |
=[Column1]>[Column2] |
Is Column1 greater than Column2? (Yes) |
15000 |
9000 |
=IF([Column1]<=[Column2], "OK", "Not OK") |
Is Column1 less than or equal to Column2? (Not OK) |
Return a logical value after comparing column contents
For a result that is a logical value (Yes or No), use the AND, OR, and NOT functions.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
15 |
9 |
8 |
=AND([Column1]>[Column2], [Column1]<[Column3]) |
Is 15 greater than 9 and less than 8? (No) |
15 |
9 |
8 |
=OR([Column1]>[Column2], [Column1]<[Column3]) |
Is 15 greater than 9 or less than 8? (Yes) |
15 |
9 |
8 |
=NOT([Column1]+[Column2]=24) |
Is 15 plus 9 not equal to 24? (No) |
For a result that is another calculation, or any other value other than Yes or No, use the IF, AND, and OR functions.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
15 |
9 |
8 |
=IF([Column1]=15, "OK", "Not OK") |
If the value in Column1 equals 15, return "OK". (OK) |
15 |
9 |
8 |
=IF(AND([Column1]>[Column2], [Column1]<[Column3]), "OK", "Not OK") |
If 15 is greater than 9 and less than 8, return "OK". (Not OK) |
15 |
9 |
8 |
=IF(OR([Column1]>[Column2], [Column1]<[Column3]), "OK", "Not OK") |
If 15 is greater than 9 or less than 8, return "OK". (OK) |
Display zeroes as blanks or dashes
To display a zero, perform a simple calculation. To display a blank or a dash, use the IF function.
Column1 |
Column2 |
Formula |
Description (possible result) |
10 |
10 |
=[Column1]-[Column2] |
Second number subtracted from the first. (0) |
15 |
9 |
=IF([Column1]-[Column2],"-",[Column1]-[Column2]) |
Returns a dash when the value is zero. (-) |
Hide error values in columns
To display a dash, #N/A, or NA in place of an error value, use the ISERROR function.
Column1 |
Column2 |
Formula |
Description (possible result) |
10 |
0 |
=[Column1]/[Column2] |
Results in an error (#DIV/0) |
10 |
0 |
=IF(ISERROR([Column1]/[Column2]),"NA",[Column1]/[Column2]) |
Returns NA when the value is an error |
10 |
0 |
=IF(ISERROR([Column1]/[Column2]),"-",[Column1]/[Column2]) |
Returns a dash when the value is an error |
Date and time formulas
如何获得当前日期:
根据了解SharePoint 2007,List计算列(Calculated)的公式(Formula)应用中没有取当天日期的函数,但可以通过这样一个方法获取:
1.首先,要在List中创建一个名为"Today"的字段列,默认为text类型即可。
2.创建名为"Calc"的计算列,然后再公式中应用如下:=DATE(YEAR(Today),MONTH(Today),DAY(Today))。
3.最后,把"Today"字段列删除掉,即可实现获取当前日期,回到List可以查看到当天日期已更新。
You can use the following formulas to perform calculations that are based on dates and times, such as adding a number of days, months, or years to a date, calculating the difference between two dates, and converting time to a decimal value.
Add dates
To add a number of days to a date, use the addition (+) operator.
Note: | |||||
When you manipulate dates, the return type of the calculated column must be set to Date and Time. | |||||
Column1 |
Column2 |
Formula |
Description (possible result) | ||
6/9/2007 |
3 |
=[Column1]+[Column2] |
Adds 3 days to 6/9/2007 (6/12/2007) | ||
12/10/2008 |
54 |
=[Column1]+[Column2] |
Adds 54 days to 12/10/2008 (2/2/2009) | ||
To add a number of months to a date, use the DATE, YEAR, MONTH, and DAY functions.
Column1 |
Column2 |
Formula |
Description (possible result) |
6/9/2007 |
3 |
=DATE(YEAR([Column1]),MONTH([Column1])+[Column2],DAY([Column1])) |
Adds 3 months to 6/9/2007 (9/9/2007) |
12/10/2008 |
25 |
=DATE(YEAR([Column1]),MONTH([Column1])+[Column2],DAY([Column1])) |
Adds 25 months to 12/10/2008 (1/10/2011) |
To add a number of years to a date, use the DATE, YEAR, MONTH, and DAY functions.
Column1 |
Column2 |
Formula |
Description (possible result) |
6/9/2007 |
3 |
=DATE(YEAR([Column1])+[Column2],MONTH([Column1]),DAY([Column1])) |
Adds 3 years to 6/9/2007 (6/9/2010) |
12/10/2008 |
25 |
=DATE(YEAR([Column1])+[Column2],MONTH([Column1]),DAY([Column1])) |
Adds 25 years to 12/10/2008 (12/10/2033) |
To add a combination of days, months, and years to a date, use the DATE, YEAR, MONTH, and DAY functions.
Column1 |
Formula |
Description (possible result) |
6/9/2007 |
=DATE(YEAR([Column1])+3,MONTH([Column1])+1,DAY([Column1])+5) |
Adds 3 years, 1 month, and 5 days to 6/9/2007 (7/14/2010) |
12/10/2008 |
=DATE(YEAR([Column1])+1,MONTH([Column1])+7,DAY([Column1])+5) |
Adds 1 year, 7 months, and 5 days to 12/10/2008 (7/15/2010) |
Calculate the difference between two dates
Use the DATEDIF function to perform this calculation.
Column1 |
Column2 |
Formula |
Description (possible result) |
01-Jan-1995 |
15-Jun-1999 |
=DATEDIF([Column1], [Column2],"d") |
Returns the number of days between the two dates (1626) |
01-Jan-1995 |
15-Jun-1999 |
=DATEDIF([Column1], [Column2],"ym") |
Returns the number of months between the dates, ignoring the year part (5) |
01-Jan-1995 |
15-Jun-1999 |
=DATEDIF([Column1], [Column2],"yd") |
Returns the number of days between the dates, ignoring the year part (165) |
Calculate the difference between two times
To present the result in the standard time format (hours:minutes:seconds), use the subtraction operator (-) and the TEXT function. For this method to work, hours must not exceed 24, and minutes and seconds must not exceed 60.
Column1 |
Column2 |
Formula |
Description (possible result) |
06/09/2007 10:35 AM |
06/09/2007 3:30 PM |
=TEXT([Column2]-[Column1],"h") |
Hours between two times (4) |
06/09/2007 10:35 AM |
06/09/2007 3:30 PM |
=TEXT([Column2]-[Column1],"h:mm") |
Hours and minutes between two times (4:55) |
06/09/2007 10:35 AM |
06/09/2007 3:30 PM |
=TEXT([Column2]-[Column1],"h:mm:ss") |
Hours, minutes, and seconds between two times (4:55:00) |
To present the result in a total that is based on one time unit, use the INT function, or HOUR, MINUTE, or SECOND function.
Column1 |
Column2 |
Formula |
Description (possible result) |
06/09/2007 10:35 AM |
06/10/2007 3:30 PM |
=INT(([Column2]-[Column1])*24) |
Total hours between two times (28) |
06/09/2007 10:35 AM |
06/10/2007 3:30 PM |
=INT(([Column2]-[Column1])*1440) |
Total minutes between two times (1735) |
06/09/2007 10:35 AM |
06/10/2007 3:30 PM |
=INT(([Column2]-[Column1])*86400) |
Total seconds between two times (104100) |
06/09/2007 10:35 AM |
06/10/2007 3:30 PM |
=HOUR([Column2]-[Column1]) |
Hours between two times, when the difference does not exceed 24 (4) |
06/09/2007 10:35 AM |
06/10/2007 3:30 PM |
=MINUTE([Column2]-[Column1]) |
Minutes between two times, when the difference does not exceed 60 (55) |
06/09/2007 10:35 AM |
06/10/2007 3:30 PM |
=SECOND([Column2]-[Column1]) |
Seconds between two times, when the difference does not exceed 60 (0) |
Convert times
To convert hours from the standard time format to a decimal number, use the INT function.
Column1 |
Formula |
Description (possible result) |
10:35 AM |
=([Column1]-INT([Column1]))*24 |
Number of hours since 12:00 AM (10.583333) |
12:15 PM |
=([Column1]-INT([Column1]))*24 |
Number of hours since 12:00 AM (12.25) |
To convert hours from a decimal number to the standard time format (hours:minutes:seconds), use the division operator and the TEXT function.
Column1 |
Formula |
Description (possible result) |
23:58 |
=TEXT(Column1/24, "hh:mm:ss") |
Hours, minutes, and seconds since 12:00 AM (00:59:55) |
2:06 |
=TEXT(Column1/24, "h:mm") |
Hours and minutes since 12:00 AM (0:05) |
Insert Julian dates
A Julian date refers to a date format that is a combination of the current year and the number of days since the beginning of the year. For example, January 1, 2007, is represented as 2007001 and December 31, 2007, is represented as 2007365. This format is not based on the Julian calendar.
To convert a date to a Julian date, use the TEXT and DATEVALUE functions.
Column1 |
Formula |
Description (possible result) |
6/23/2007 |
=TEXT([Column1],"yy")&TEXT(([Column1]-DATEVALUE("1/1/"& TEXT([Column1],"yy"))+1),"000") |
Date in Julian format, with a two-digit year (07174) |
6/23/2007 |
=TEXT([Column1],"yyyy")&TEXT(([Column1]-DATEVALUE("1/1/"&TEXT([Column1],"yy"))+1),"000") |
Date in Julian format, with a four-digit year (2007174) |
To convert a date to a Julian date that is used in astronomy, use the constant 2415018.50. This formula works only for dates after 3/1/1901, and if you are using the 1900 date system.
Column1 |
Formula |
Description (possible result) |
6/23/2007 |
=[Column1]+2415018.50 |
Date in Julian format, used in astronomy (2454274.50) |
Show dates as the day of the week
To convert dates to the text for the day of the week, use the TEXT and WEEKDAY functions.
Column1 |
Formula |
Description (possible result) |
19-Feb-2007 |
=TEXT(WEEKDAY([Column1]), "dddd") |
Calculates the day of the week for the date and returns the full name of the day (Monday) |
3-Jan-2008 |
=TEXT(WEEKDAY([Column1]), "ddd") |
Calculates the day of the week for the date and returns the abbreviated name of the day (Thu) |
Mathematical formulas
You can use the following formulas to perform a variety of mathematical calculations, such as adding, subtracting, multiplying, and dividing numbers; calculating the average or median of numbers; rounding a number; and counting values.
Add numbers
To add numbers in two or more columns in a row, use the addition operator (+) or the SUM function.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
6 |
5 |
4 |
=[Column1]+[Column2]+[Column3] |
Adds the values in the first three columns (15) |
6 |
5 |
4 |
=SUM([Column1],[Column2],[Column3]) |
Adds the values in the first three columns (15) |
6 |
5 |
4 |
=SUM(IF([Column1]>[Column2], [Column1]-[Column2], 10), [Column3]) |
If Column1 is greater than Column2, adds the difference and Column3. Else add 10 and Column3 (5) |
Subtract numbers
To subtract numbers in two or more columns in a row, use the subtraction operator (-) or the SUM function with negative numbers.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
15000 |
9000 |
-8000 |
=[Column1]-[Column2] |
Subtracts 9000 from 15000 (6000) |
15000 |
9000 |
-8000 |
=SUM([Column1], [Column2], [Column3]) |
Adds numbers in the first three columns, including negative values (16000) |
Calculate the difference between two numbers as a percentage
Use the subtraction (-) and division (/) operators and the ABS function.
Column1 |
Column2 |
Formula |
Description (possible result) |
2342 |
2500 |
=([Column2]-[Column1])/ABS([Column1]) |
Percentage change (6.75% or 0.06746) |
Multiply numbers
To multiply numbers in two or more columns in a row, use the multiplication operator (*) or the PRODUCT function.
Column1 |
Column2 |
Formula |
Description (possible result) |
5 |
2 |
=[Column1]*[Column2] |
Multiplies the numbers in the first two columns (10) |
5 |
2 |
=PRODUCT([Column1], [Column2]) |
Multiplies the numbers in the first two columns (10) |
5 |
2 |
=PRODUCT([Column1],[Column2],2) |
Multiplies the numbers in the first two columns and the number 2 (20) |
Divide numbers
To divide numbers in two or more columns in a row, use the division operator (/).
Column1 |
Column2 |
Formula |
Description (possible result) |
15000 |
12 |
=[Column1]/[Column2] |
Divides 15000 by 12 (1250) |
15000 |
12 |
=([Column1]+10000)/[Column2] |
Adds 15000 and 10000, and then divides the total by 12 (2083) |
Calculate the average of numbers
The average is also called the mean. To calculate the average of numbers in two or more columns in a row, use the AVERAGE function.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
6 |
5 |
4 |
=AVERAGE([Column1], [Column2],[Column3]) |
Average of the numbers in the first three columns (5) |
6 |
5 |
4 |
=AVERAGE(IF([Column1]>[Column2], [Column1]-[Column2], 10), [Column3]) |
If Column1 is greater than Column2, calculate the average of the difference and Column3. Else calculate the average of the value 10 and Column3 (2.5) |
Calculate the median of numbers
The median is the value at the center of an ordered range of numbers. Use the MEDIAN function to calculate the median of a group of numbers.
A |
B |
C |
D |
E |
F |
Formula |
Description (result) |
10 |
7 |
9 |
27 |
0 |
4 |
=MEDIAN(A, B, C, D, E, F) |
Median of numbers in the first 6 columns (8) |
Calculate the smallest or largest number in a range
To calculate the smallest or largest number in two or more columns in a row, use the MIN and MAX functions.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
10 |
7 |
9 |
=MIN([Column1], [Column2], [Column3]) |
Smallest number (7) |
10 |
7 |
9 |
=MAX([Column1], [Column2], [Column3]) |
Largest number (10) |
Count values
To count numeric values, use the COUNT function.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
Apple |
12/12/2007 |
=COUNT([Column1], [Column2], [Column3]) |
Counts the number of columns that contain numeric values. Excludes date and time, text, and null values (0) | |
$12 |
#DIV/0! |
1.01 |
=COUNT([Column1], [Column2], [Column3]) |
Counts the number of columns that contain numeric values, but excludes error and logical values (2) |
Increase or decrease a number by a percentage
Use the percent (%) operator to perform this calculation.
Column1 |
Column2 |
Formula |
Description (possible result) |
23 |
3% |
=[Column1]*(1+5%) |
Increases number in Column1 by 5% (24.15) |
23 |
3% |
=[Column1]*(1+[Column2]) |
Increases number in Column1 by the percent value in Column2: 3% (23.69) |
23 |
3% |
=[Column1]*(1-[Column2]) |
Decreases number in Column1 by the percent value in Column2: 3% (22.31) |
Raise a number to a power
Use the exponentiation operator (^) or the POWER function to perform this calculation.
Column1 |
Column2 |
Formula |
Description (possible result) |
5 |
2 |
=[Column1]^[Column2] |
Calculates five squared (25) |
5 |
3 |
=POWER([Column1], [Column2]) |
Calculates five cubed (125) |
Round a number
To round up a number, use the ROUNDUP, ODD, or EVEN function.
Column1 |
Formula |
Description (possible result) |
20.3 |
=ROUNDUP([Column1],0) |
Rounds 20.3 up to the nearest whole number (21) |
-5.9 |
=ROUNDUP([Column1],0) |
Rounds -5.9 up to the nearest whole number (-5) |
12.5493 |
=ROUNDUP([Column1],2) |
Rounds 12.5493 up to the nearest hundredth, two decimal places (12.55) |
20.3 |
=EVEN([Column1]) |
Rounds 20.3 up to the nearest even number (22) |
20.3 |
=ODD([Column1]) |
Rounds 20.3 up to the nearest odd number (21) |
To round down a number, use the ROUNDDOWN function.
Column1 |
Formula |
Description (possible result) |
20.3 |
=ROUNDDOWN([Column1],0) |
Rounds 20.3 down to the nearest whole number (20) |
-5.9 |
=ROUNDDOWN([Column1],0) |
Rounds -5.9 down to the nearest whole number (-6) |
12.5493 |
=ROUNDDOWN([Column1],2) |
Rounds 12.5493 down to the nearest hundredth, two decimal places (12.54) |
To round a number to the nearest number or fraction, use the ROUND function.
Column1 |
Formula |
Description (possible result) |
20.3 |
=ROUND([Column1],0) |
Rounds 20.3 down, because the fractional part is less than .5 (20) |
5.9 |
=ROUND([Column1],0) |
Rounds 5.9 up, because the fractional part is greater than .5 (6) |
-5.9 |
=ROUND([Column1],0) |
Rounds -5.9 down, because the fractional part is less than -.5 (-6) |
1.25 |
=ROUND([Column1], 1) |
Rounds the number to the nearest tenth (one decimal place). Because the portion to be rounded is 0.05 or greater, the number is rounded up (result: 1.3) |
30.452 |
=ROUND([Column1], 2) |
Rounds the number to the nearest hundredth (two decimal places). Because the portion to be rounded, 0.002, is less than 0.005, the number is rounded down (result: 30.45) |
To round a number to the significant digit above 0, use the ROUND, ROUNDUP, ROUNDDOWN, INT, and LEN functions.
Column1 |
Formula |
Description (possible result) |
5492820 |
=ROUND([Column1],3-LEN(INT([Column1]))) |
Rounds the number to 3 significant digits (5490000) |
22230 |
=ROUNDDOWN([Column1],3-LEN(INT([Column1]))) |
Rounds the bottom number down to 3 significant digits (22200) |
5492820 |
=ROUNDUP([Column1], 5-LEN(INT([Column1]))) |
Rounds the top number up to 5 significant digits (5492900) |
Text formulas
You can use the following formulas to manipulate text, such as combining or concatenating the values from multiple columns, comparing the contents of columns, removing characters or spaces, and repeating characters.
Change the case of text
To change the case of text, use the UPPER, LOWER, or PROPER function.
Column1 |
Formula |
Description (possible result) |
nina Vietzen |
=UPPER([Column1]) |
Changes text to uppercase (NINA VIETZEN) |
nina Vietzen |
=LOWER([Column1]) |
Changes text to lowercase (nina vietzen) |
nina Vietzen |
=PROPER([Column1]) |
Changes text to title case (Nina Vietzen) |
Combine first and last names
To combine first and last names, use the ampersand operator (&) or the CONCATENATE function.
Column1 |
Column2 |
Formula |
Description (possible result) |
Carlos |
Carvallo |
=[Column1]&[Column2] |
Combines the two strings (CarlosCarvallo) |
Carlos |
Carvallo |
=[Column1]&" "&[Column2] |
Combines the two strings, separated by a space (Carlos Carvallo) |
Carlos |
Carvallo |
=[Column2]&", "&[Column1] |
Combines the two strings, separated by a comma and a space (Carvallo, Carlos) |
Carlos |
Carvallo |
=CONCATENATE([Column2], ",", [Column1]) |
Combines the two strings, separated by a comma (Carvallo,Carlos) |
Combine text and numbers from different columns
To combine text and numbers, use the CONCATENATE function, the ampersand operator (&), or the TEXT function and the ampersand operator.
Column1 |
Column2 |
Formula |
Description (possible result) |
Yang |
28 |
=[Column1]&" sold "&[Column2]&" units." |
Combines contents above into a phrase (Yang sold 28 units.) |
Dubois |
40% |
=[Column1]&" sold "&TEXT([Column2],"0%")&" of the total sales." |
Combines contents above into a phrase (Dubois sold 40% of the total sales.) Note The TEXT function appends the formatted value of Column2 instead of the underlying value, which is 0.4. |
Yang |
28 |
=CONCATENATE([Column1]," sold ",[Column2]," units.") |
Combines contents above into a phrase (Yang sold 28 units.) |
Combine text with a date or time
To combine text with a date or time, use the TEXT function and the ampersand operator (&).
Column1 |
Column2 |
Formula |
Description (possible result) |
Billing Date |
5-Jun-2007 |
="Statement date: "&TEXT([Column2], "d-mmm-yyyy") |
Combines text with a date (Statement date: 5-Jun-2007) |
Billing Date |
5-Jun-2007 |
=[Column1]&" "&TEXT([Column2], "mmm-dd-yyyy") |
Combines text and date from different columns into one column (Billing Date Jun-05-2007) |
Compare column contents
To compare one column to another column or a list of values, use the EXACT and OR functions.
Column1 |
Column2 |
Formula |
Description (possible result) |
BD122 |
BD123 |
=EXACT([Column1],[Column2]) |
Compares contents of first two columns (No) |
BD122 |
BD123 |
=EXACT([Column1], "BD122") |
Compares contents of Column1 and the string "BD122" (Yes) |
Determine whether a column value or a part of it matches specific text
To determine whether a column value or a part of it matches specific text, use the IF, FIND, SEARCH, and ISNUMBER functions.
Column1 |
Formula |
Description (possible result) |
Vietzen |
=IF([Column1]="Vietzen", "OK", "Not OK") |
Determines whether Column1 is Vietzen (OK) |
Vietzen |
=IF(ISNUMBER(FIND("v",[Column1])), "OK", "Not OK") |
Determines whether Column1 contains the letter v (OK) |
BD123 |
=ISNUMBER(FIND("BD",[Column1])) |
Determines whether Column1 contains BD (Yes) |
Count nonblank columns
To count nonblank columns, use the COUNTA function.
Column1 |
Column2 |
Column3 |
Formula |
Description (possible result) |
Sales |
19 |
=COUNTA([Column1], [Column2]) |
Counts the number of nonblank columns (2) | |
Sales |
19 |
=COUNTA([Column1], [Column2], [Column3]) |
Counts the number of nonblank columns (2) |
Remove characters from text
To remove characters from text, use the LEN, LEFT, and RIGHT functions.
Column1 |
Formula |
Description (possible result) |
Vitamin A |
=LEFT([Column1],LEN([Column1])-2) |
Returns 7 (9-2) characters, starting from left (Vitamin) |
Vitamin B1 |
=RIGHT([Column1], LEN([Column1])-8) |
Returns 2 (10-8) characters, starting from right (B1) |
Remove spaces from the beginning and end of a column
To remove spaces from a column, use the TRIM function.
Column1 |
Formula |
Description (possible result) |
Hello there! |
=TRIM([Column1]) |
Removes the spaces from the beginning and end (Hello there!) |
Repeat a character in a column
To repeat a character in a column, use the REPT function.
Formula |
Description (possible result) |
=REPT(".",3) |
Repeats a period 3 times (...) |
=REPT("-",10) |
Repeats a dash 10 times (----------) |
SPS中您可以使用列表或库中的公式和函数以多种方式计算数据。通过向列表或库中添加计算列,可以为来自其他列的数据创建公式,并可执行函数以计算日期和时间、运行数学方程或处理文字。例如,在任务列表中,可以使用一个列根据“开始日期”和“完成日期”列来计算完成每项任务所需的天数。
注释 本文介绍与使用公式和函数有关的基本概念。有关具体某个函数的特定信息,请参阅有关该函数的文章。
公式概述
函数概述
在公式中使用列引用
在公式中使用常量
在公式中使用运算符
公式概述
公式是对列表或库中的值进行计算的等式。公式以等号 (=) 开头。例如,在下面的公式中,结果等于 2 乘以 3 再加 5。
=5+2*3
可以在计算列中使用公式,也可以使用公式计算某一列的默认值。公式中可以包含函数 (函数:函数是预先编写的公式,可以对一个或多个值执行运算,并返回一个或多个值。函数可以简化和缩短工作表中的公式,尤其在用公式执行很长或复杂的计算时。)、列引用、运算符 (运算符:一个标记或符号,指定表达式内执行的计算的类型。有数学、比较、逻辑和引用运算符等。)和常量 (常量:不进行计算的值,因此也不会发生变化。例如,数字 210 以及文本“每季度收入”都是常量。表达式以及表达式产生的值都不是常量。),如下例所示。
=PI()*[Result]^2
元素 | 说明 |
---|---|
函数 | PI() 函数返回圆周率 pi 的值 3.141592654。 |
引用(或列名) | [Result] 表示当前行的“Result”列中的值。 |
常量 | 直接输入到公式中的数字或文本值,如 2。 |
运算符 | *(星号)运算符执行乘法运算,^(插入符号)运算符表示将数字乘幂。 |
公式可以使用上表中的一个或多个元素。下面是一些按照复杂程度排序的公式的示例。
简单公式(如 =128+345)
下列公式包含常量和运算符。
示例 | 说明 |
---|---|
=128+345 | 将 128 与 345 相加 |
=5^2 | 计算 5 的平方 |
包含列引用的公式(如 =[Revenue] >[Cost])
下列公式引用同一个列表或库中的其他列。
示例 | 说明 |
---|---|
=[Revenue] | 使用“Revenue”列中的值。 |
=[Revenue]*10/100 | “Revenue”列中的值的 10%。 |
=[Revenue] > [Cost] | 如果“Revenue”列中的值大于“Cost”列中的值,则返回“Yes”。 |
调用函数的公式(如 =AVERAGE(1, 2, 3, 4, 5))
下列公式调用内置函数。
示例 | 说明 |
---|---|
=AVERAGE(1, 2, 3, 4, 5) | 返回一组数值的平均值。 |
=MAX([Q1], [Q2], [Q3], [Q4]) | 返回一组数值中的最大值。 |
=IF([Cost]>[Revenue], "Not OK", "OK") | 如果成本大于收入,则返回“Not OK”。否则,返回“OK”。 |
=DAY("15-Apr-2008") | 返回日期中的天。此公式返回数字 15。 |
含有嵌套函数的公式(如 =SUM(IF([A]>[B], [A]-[B], 10), [C]))
下列公式将一个或多个函数指定为函数参数。
示例 | 说明 |
---|---|
=SUM(IF([A]>[B], [A]-[B], 10), [C]) | IF 函数返回列 A 与列 B 中值的差值或 10。
SUM 函数将 IF 函数的返回值与列 C 中的值相加。 |
=DEGREES(PI()) | PI 函数返回数字 3.141592654。
DEGREES 函数将弧度值转换为角度值。此公式返回数值 180。 |
=ISNUMBER(FIND("BD",[Column1])) | FIND 函数在 Column1 中搜索字符串 BD,并返回该字符串的起始位置。如果未找到该字符串,则返回一个错误值。
如果 FIND 函数返回一个数值,则 ISNUMBER 函数返回“Yes”。否则,它返回“No”。 |
函数概述
函数是预定义的公式,这些公式使用叫做参数的特定值按特定顺序或结构进行计算。函数可用于执行简单或复杂的计算。例如,下面的 ROUND 函数实例可将“Cost”列的数字四舍五入为小数点后两位。
=ROUND([Cost], 2)
学习函数和公式时,下列词汇很有帮助:
结构 函数的结构以等号 (=) 开始,后跟函数名、左括号、以逗号分隔的函数参数,以右括号结束。
函数名 列表或库支持的函数的名称。每个函数都引用特定个数的参数,并对这些参数进行处理,然后返回一个值。
参数 参数可以是数字、文本、逻辑值(如 True 或 False)或列引用。指定的参数必须是该参数的有效值。参数也可以是常量、公式或其他函数。
在某些情况下,可能需要将一个函数作为另一个函数的一个参数使用。例如,下面的公式使用了嵌套的 AVERAGE 函数,将结果与两列的值之和进行比较。
=AVERAGE([Cost1], SUM([Cost2]+[Discount]))
有效返回值 当函数作为参数使用时,其返回值的类型必须与参数所用值的类型相同。例如,如果参数使用“Yes”或“No”,则嵌套函数必须返回“Yes”或“No”;否则,列表或库将显示 #VALUE! 错误值。
嵌套层限制 一个公式最多可以含有八层嵌套函数。当函数 B 作为函数 A 中的参数使用时,函数 B 是第二层函数。例如,在上面的示例中,SUM 函数是第二层函数,因为它是 AVERAGE 函数的参数。在 SUM 函数中嵌套的函数是第三层函数,依此类推。
注释
在公式中使用列引用
引用标识当前行中的一个单元格,并向列表或库指示在何处搜索要在公式中使用的值或数据。例如,[Cost] 引用当前行中“Cost”列中的值。如果当前行中“Cost”列的值为 100,则 =[Cost]*3 返回 300。
通过引用,可以在一个或多个公式中使用列表或库的不同列中所包含的数据。可以在公式中引用下列数据类型的列:单行文本、数字、货币、日期和时间、选择、是/否以及计算列。
可以使用列的显示名称在公式中引用该列。如果名称中包含空格或特殊字符,则必须将名称括在方括号 ([ ]) 中。引用不区分大小写。例如,可以在公式中使用 [Unit Price] 或 [unit price] 来引用“Unit Price”这一列。
注释
在公式中使用常量
常量是不用计算的值。例如,日期 10/9/2008、数字 210 以及文本“季度收入”都是常量。常量可以是下列数据类型:
- String(示例:=[Last Name] = "Smith")
String 常量括在引号中,最多可以包含 255 个字符。
- Number(示例:=[Cost] >= 29.99)
Numeric 常量可以包含小数位数,可以是正数或负数。
- Date(示例:=[Date] > DATE(2007,7,1))
Date 常量要求使用 DATE(year,month,day) 函数。
- Boolean(示例:=IF([Cost]>[Revenue], "Loss", "No Loss")
“Yes”和“No”是 Boolean 常量。可以在条件表达中使用 Boolean 常量。在上面的示例中,如果“Cost”大于“Revenue”,则 IF 函数返回“Yes”,该公式返回字符串“Loss”。如果“Cost”等于或小于“Revenue”,则该函数返回“No”,并且该公式返回字符串“No Loss”。
在公式中使用运算符
运算符指定要对公式中的元素执行的运算的类型。列表和库支持三种不同类型的运算符:算术运算符、比较运算符和文本运算符。
算术运算符
可使用下列算术运算符来执行加法、减法或乘法等基本数学运算,组合数字或者产生数字结果。
算术运算符 | 含义(示例) |
---|---|
+(加号) | 加法运算 (3+3) |
–(减号) | 减法运算 (3–1) 负数 (–1) |
*(星号) | 乘法运算 (3*3) |
/(正斜杠) | 除法运算 (3/3) |
%(百分号) | 百分比 (20%) |
^(插入符号) | 乘幂运算 (3^2) |
比较运算符
可以使用下列运算符对两个值进行比较。使用这些运算符对两个值进行比较时,结果是一个逻辑值“Yes”或“No”。
比较运算符 | 含义(示例) |
---|---|
=(等号) | 等于 (A=B) |
>(大于号) | 大于 (A>B) |
<(小于号) | 小于 (A<B) |
>=(大于等于号) | 大于或等于 (A>=B) |
<=(小于等于号) | 小于或等于 (A<=B) |
<>(不等号) | 不等于 (A<>B) |
文本运算符
使用与号 (&) 联接或连接一个或更多个文本字符串以产生一串文本。
文本运算符 | 含义(示例) |
---|---|
&(与号) | 将两个值连接或联接起来产生一个连续的文本值 ("North"&"wind") |
列表或库执行公式中的运算的顺序
公式按照特定的顺序计算值。公式可以使用等号(=)开头。等号后面紧跟着要计算的元素(操作数),它们之间用运算符分隔。根据公式中每个运算符的特定顺序,列表和库从左向右计算公式。
运算符优先级
如果一个公式中用到多个运算符,列表和库将按下表所示的顺序进行运算。如果公式中包含具有相同优先级的运算符,例如,公式中同时包含乘法运算符和除法运算符,则列表和库将从左到右计算运算符。
运算符 | 说明 |
---|---|
– | 负号(例如 –1) |
% | 百分比 |
^ | 乘幂 |
* 和 / | 乘和除 |
+ 和 – | 加和减 |
& | 连接(将两个文本串连接在一起) |
= < > <= >= <> | 比较 |
使用括号
要更改求值顺序,请将公式中要先计算的部分用括号括起来。例如,下面公式的结果是 11,因为列表或库先进行乘法运算后进行加法运算。该公式将 2 与 3 相乘,然后再加上 5,所得的数值就是最终结果。
=5+2*3
与此相反,如果使用括号改变语法,则列表或库先将 5 与 2 相加,再用所得的结果乘以 3,得到的最终结果为 21。
=(5+2)*3
在下面的示例中,公式中第一部分周围的括号强制列表或库先计算 [Cost]+25,然后用结果除以列 EC1 和 EC2 中的值之和。