Documentation/Calc 関数/SUMIFS
TDF LibreOffice Document Liberation Project Community Blogs Weblate Nextcloud Redmine Ask LibreOffice Donate
Function name:
SUMIFS
Category:
Mathematical
Summary:
セル範囲内の数値の合計を計算します。加算されるセルは、複数の条件を使用して決定されます。 SUMIFS と Calc の SUMIF 関数の主な違いは、後者が 1 つの条件のみを評価するように制限されていることです。
SUMIFS に渡される条件では、ワイルドカードまたは正規表現を使用できます。
Syntax:
SUMIFS(合計範囲; 範囲 1; 条件 1[; 範囲 2; 条件 2[; … [; 範囲 127; 条件 127]]])
Returns:
関連するセルの数値を加算した結果である実数を返します。
Arguments:
合計範囲 引数
合計範囲 は合計するセルを指定します。通常、合計範囲 は次のいずれかの形式になります。
- セル範囲への参照 (例えば、A1:A25)。参照連結演算子 (~) を使用しない場合があります。
- 名前付き範囲の名前。
- データベース範囲の名前。
範囲 引数
範囲 1 は、条件 1 と照合されるセルのセットを指定し、合計範囲に対してリストされた形式の 1 つを取ります。範囲 1 は、合計範囲と同じ次元を持つ必要があります。
範囲 2、...、範囲 127 は、範囲 1 と同じ意味です。
条件 引数
条件 1 は 範囲 1 内のセル、またはその条件を含むセルと照合するための条件です。条件 1 は、次のいずれかの形式になります。
- A number, such as 34.5. Dates and logical values (TRUE or FALSE) are treated as numbers.
- An expression, such as 2/3, SQRT($D$1), or DATE(2021; 11; 1).
- A text string, such as "golf" or "<>10".
SUMIFS looks for cells in Range 1 that are equal to Criterion 1, unless Criterion 1 is a text string that starts with a comparator (>, <, >=, <=, =, or <>). In the latter case SUMIFS compares the cells in Range 1 with the remainder of the text string (interpreted as a number if possible and text otherwise). For example, the condition ">4.5" tests if the content of each cell is greater than the number 4.5, the condition "<dog" tests if the content of each cell comes alphabetically before the text "dog", and the condition "<>2021-11-01" tests if the content of each cell is not equal to the specified date.
Criterion 1 supports the following specific behaviors:
- The string "=" matches empty cells. For example the formula
=SUMIFS(A1:A10; B1:B10; "=")
returns the sum of all values in the range A1:A10 if all cells in the range B1:B10 are empty. Note that "=0" does not match empty cells. - The string "<>" matches non-empty cells. For example the formula
=SUMIFS(A1:A10; C1:C10; "<>")
returns the sum of all values in the range A1:A10 if there are no empty cells in the range C1:C10. - If the value after the <> comparator is not empty, then Criterion 1 matches any cell content except that value, including empty cells.
Criterion 2, ..., Criterion 127 have the same meaning as Criterion 1.
Error conditions
- If any cell range passed as an argument contains a reference concatenation operator (~), then SUMIFS reports an invalid argument error (エラー:502).
- All the cell ranges passed as arguments (SumRange and Range 1, …, Range 127) must occupy the same number of rows and the same number of columns. If this is not the case, then SUMIFS reports an invalid argument error (エラー:502).
- If the Range n and Criterion n arguments are not correctly paired, then SUMIFS reports a variable missing error (エラー:511).
Additional details:
Details specific to SUMIFS function
- The default matching performed by SUMIFS is case-insensitive. However, a case-sensitive match can be carried out when using a regular expression by including a mode modifier "(?-i)" within the regular expression, as demonstrated by one of the examples below.
- The behavior of SUMIFS is affected by several settings available on the ▸ ▸ ▸ dialog ( ▸ ▸ ▸ on macOS).
- If the checkbox is ticked for Search criteria = and <> must apply to whole cells, then the condition "red" will match only "red"; if unticked it will match "red", "Fred", "red herring".
- If the checkbox is ticked for Enable wildcards in formulas, the condition will match using wildcards - so for example "b?g" will match "bag", "beg", "big", "bog", and "bug".
- If the checkbox is ticked for Enable regular expressions in formulas, the condition will match using regular expressions - so for example "r.d" will match "red", "rid", and "rod", while "red.*" will match "red", "redraw", and "redden".
- The setting of the Case sensitive checkbox has no impact on the operation of SUMIFS.
Calc の正規表現に関する一般事項
- 正規表現とは、一致させるテキストのパターンを定義する文字列です。より詳細で一般的な背景情報は、Regular expression ページにあります。
- 正規表現は多くのドメインで広く使用されており、様々な正規表現プロセッサが利用可能です。Calc では、International Components for Unicode (ICU) のオープンソース正規表現パッケージ を採用しています。ICU 正規表現の構文の完全な定義を含む詳細については、Regular Expressions のドキュメントを参照してください。
- さらに、LibreOffice のヘルプ・システムは、高水準の 正規表現リスト を提供します。
- Calc の正規表現エンジンは、番号付きキャプチャ・グループ をサポートしています。これにより、一致するサブ範囲を識別し、置換テキスト内で使用できます。括弧は、正規表現のコンポーネントをグループ化し、番号付きキャプチャ・グループを作成するために使用されます。キャプチャ・グループを置換テキストに挿入するには、"$n" 形式を使用します。ここで、"n" はキャプチャ・グループの番号です。
Calc のワイルドカードに関する一般事項
ワイルドカードは、一部の Calc 関数に引数として渡される検索文字列で使用できる特殊文字です。また、検索と置換 ダイアログで検索条件を定義するためにも使用できます。ワイルドカードを使用すると、単一の検索文字列でより高度な検索パラメータを定義できます。
Calc は、現在のアプリケーションの設定に応じて、引数としてワイルドカードまたは正規表現をサポートします。既定では、正規表現ではなくワイルドカードがサポートされます。
ワイルドカードがサポートされていることを確認するには、 数式でワイルドカードを使用する
が選択されているかどうかを確認します。このダイアログを使用して正規表現に切り替えるには、数式で正規表現を使用する
を選択するか、ワイルドカードも正規表現もサポートしないように選択します。
次の表に、Calc でサポートされているワイルドカードを示します。
ワイルドカード | 説明 |
---|---|
? (クエスチョン・マーク) | 任意の 1 文字に一致します。たとえば、検索文字列 "b?g" は "bag" および "beg" に一致しますが、"boog" または "mug" には一致しません。 "?" は正確に 1 文字に一致する必要があるため、"bg" にも一致しないことに注意してください。"?" ワイルドカードは、0 文字の一致には対応しません。 |
* (アスタリスク) | 空の文字列を含む任意の文字列と一致します。たとえば、検索文字列 "*cast" は、"cast"、"forecast" および“outcast”と一致しますが、デフォルトの Calc 設定を使用する場合 "forecaster" とは一致しません。 ▸ ▸ ▸ でオプション 検索条件 = と <> はセル全体に適用 が無効になっている場合、"forecaster" は "*cast" の検索文字列を使用し一致させることができます。
|
~ (チルダ) | チルダ文字の直後に続く疑問符、アスタリスク、または チルダ文字の特別な意味をエスケープします。 例えば、検索文字列 "why~?" は "why?" に一致しますが、 "whys" や "why~s" には一致しません。 |
ワイルドカードの比較では大文字と小文字が区別されないため、 "A?" は "A1" と "a1" の両方に一致します。
これらのワイルドカードは、Calc と Microsoft Excel の両方でサポートされています。したがって、2 つのアプリケーション間の相互運用性が必要な場合は、正規表現ではなくワイルドカードを使用することを選択します。逆に、相互運用性が必要でない場合は、より強力な検索機能のために正規表現の使用を検討してください。
Examples:
Stationery sales examples
Consider the following table showing sales and revenue information for a small stationery supplier. The string "N/A" refers to products that were not available for supply during the period covered by the data.
A | B | C | |
---|---|---|---|
1 | Product | Sales | Revenue |
2 | Pencil | 20 | $65 |
3 | Pen | 35 | $85 |
4 | Notebook | 20 | $190 |
5 | Book | 17 | $180 |
6 | Pencil case | N/A | N/A |
In all examples based on this table, it should be noted that row 6 for pencil cases contains no numeric data and so will never contribute to the result of SUMIFS, whatever criteria are specified.
Formula | Description | Returns |
---|---|---|
=SUMIFS(B2:B6; B2:B6; ">=20") | Here the function sums the numeric Sales data that are greater than or equal to 20. | 75 |
=SUMIFS(C2:C6; B2:B6; ">=20"; C2:C6; ">70") | Here the function locates entries greater than or equal to 20 in the Sales data that also have a value greater than $70 in the Revenue data, and sums the corresponding numeric entries in the Revenue data. | $275 |
=SUMIFS(C2:C6; B2:B6; ">"&MIN(B2:B6); B2:B6; "<"&MAX(B2:B6)) | Here the function calculates the sum of the numeric entries in the Revenue data that correspond to all values in the Sales data except the minimum and maximum. | $255 |
=SUMIFS(C2:C6; A2:A6; "pen.*"; B2:B6; "<"&MAX(B2:B6)) | This example will only work as described here if regular expressions are enabled. Here the function locates entries in the Product data that begin with the characters "pen" and have a value in the Sales data that is not the maximum, and sums the corresponding numeric entries in the Revenue data. | $65 |
=SUMIFS(C2:C6; A2:A6; E2&".*"; B2:B6; "<"&MAX(B2:B6)) where cell E2 contains the string "pen" (entered without typing the double quotes). | This example will only work as described here if regular expressions are enabled. If you need to change a criterion easily, you may want to specify it in a separate cell and use a reference to this cell in the condition of the SUMIFS function. Here the link to the cell is substituted with its content, giving the same result as the previous example. | $65 |
Sporting equipment sales examples
The examples in this subsection are based on a small database of sales data for sports equipment, with the data organized as in the following table.
A | B | C | D | E | |
---|---|---|---|---|---|
1 | Date | Sales Value | Category | Region | Employee |
2 | 2021-10-02 | $1,508 | Golf | East | Hans |
3 | 2021-10-02 | $410 | Tennis | North | Kurt |
4 | 2021-10-02 | $2,340 | Sailing | South | Ute |
5 | 2021-10-03 | $4,872 | Tennis | East | Brigitte |
6 | 2021-10-06 | $3,821 | Tennis | South | Fritz |
7 | 2021-10-06 | $2,623 | Tennis | East | Fritz |
8 | 2021-10-07 | $3,739 | Golf | South | Fritz |
9 | 2021-10-08 | $4,195 | Golf | West | Ute |
10 | 2021-10-10 | $2,023 | Golf | East | Hans |
Formula | Description | Returns |
---|---|---|
=SUMIFS(B2:B10; B2:B10; ">=4000") | Here the function sums the numeric entries in the Sales Value data that are greater than or equal to $4,000. This formula is equivalent to both =SUMIF(B2:B10; ">=4000") and =SUMIF(B2:B10; ">=4000"; B2:B10) . |
$9,067 |
=SUMIFS(B2:B10; E2:E10; "ute") | Here the function locates the entries for Ute in the Employee data and sums the corresponding numeric entries in the Sales Value data. This formula is equivalent to =SUMIF(E2:E10; "ute"; B2:B10) and this re-ordering of arguments highlights a key difference between the two functions - SumRange is the third argument for SUMIF and the first argument for SUMIFS. |
$6,535 |
=SUMIFS(B2:B10; CategoryData; "golf") where the named range CategoryData has been created to cover the cell range C2:C10. | Here the function locates the entries for Golf in the Category data and sums the corresponding numeric entries in the SUMIFSSales Value data. | $11,465 |
=SUMIFS(B2:B10; D2:D10; F1; E2:E10; F2) where cells F1 and F2 contain the text strings ">=south" and "ute" respectively (both entered without typing the double quotes). | Here the function locates the entries for South and West in the Region data that also have Ute in the Employee data, and sums the corresponding numeric entries in the Sales Value data. | $6,535 |
=SUMIFS(B2:B10; A2:A10; DATE(2021; 10; 2); C2:C10; "tennis") | Here the function locates the entries for 2021-10-02 in the Date column that also have Tennis in the Category data, and sums the corresponding numeric entries in the Sales Value data. | $410 |
=SUMIFS(B2:B10; A2:A10; ">="&DATE(2021; 10; 6); E2:E10; "<>"&E8) | Here the function locates the entries dated on or after 2021-10-06 in the Date column that do not have Fritz in the Employee data, and sums the corresponding numeric entries in the Sales Value data. | $6,218 |
=SUMIFS(B2:B10; C2:C10; "tennis"; D2:D10; "east"; E2:E10; "fritz") | Here the function locates the entries that have Tennis in the Category data, East in the Region data and Fritz in the Employee data. It sums the corresponding numeric entries in the Sales Value data. | $2,623 |
=SUMIFS(B2:B10; D2:D10; "????"; E2:E10; "*e") | This example will only work as described here if wildcards are enabled. Here the function locates the four-character entries in the Region data (East and West) that also have an entry in the Employee data that ends with the letter "e" or "E" (Brigitte and Ute). It sums the corresponding numeric entries in the Sales Value data. | $9,067 |
=SUMIFS(B2:B10; C2:C10; "^t.*"; D2:D10; ".*h") | This example will only work as described here if regular expressions are enabled. Here the function locates the entries for Tennis in the Category data that start with the letter "t" or "T" (Tennis) that also have an entry in the Region data that ends with the letter "h" or "H" (North and South). It sums the corresponding numeric entries in the Sales Value data. | $4,231 |
=SUMIFS(B2:B10; E2:E10; "(?-i)ute") | This example will only work as described here if regular expressions are enabled. The "(?-i)" mode modifier within the regular expression changes to a case-sensitive match and so no entries are found in the Employee data. Contrast this with the second example in this table. | $0 |
Additional examples
For more examples, download and view this Calc spreadsheet.
Related LibreOffice functions:
ODF standard:
Related (or similar) Excel functions:
SUMIFS