You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: powerapps-docs/maker/canvas-apps/functions/function-forall.md
+29-23Lines changed: 29 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,39 +15,45 @@ search.app:
15
15
- PowerApps
16
16
---
17
17
# ForAll function in Power Apps
18
-
Calculates values and performs actions for all [records](../working-with-tables.md#records) of a [table](../working-with-tables.md).
18
+
19
+
Calculates values and performs actions for all the [records](../working-with-tables.md#records) in a [table](../working-with-tables.md).
19
20
20
21
## Description
21
-
The **ForAll** function evaluates a formula for all records of a table. The formula can calculate a value and/or perform actions, such as modifying data or working with a connection. Use the [**With** function](function-with.md) to evaluate a formula for a single record.
22
+
23
+
The **ForAll** function evaluates a formula for all the records if a table. The formula can calculate a value and/or perform actions, such as modifying data or working with a connection. Use the [**With** function](function-with.md) to evaluate the formula for a single record.
22
24
23
25
Use the [**Sequence** function](function-sequence.md) with the **ForAll** function to iterate based on a count.
The result of each formula evaluation is returned in a table, in the same order as the input table.
29
32
30
-
If the result of the formula is a single value, the resulting table will be a singlecolumn table. If the result of the formula is a record, the resulting table will contain records with the same columns as the result record.
33
+
If the result of the formula is a single value, the resulting table will be a single-column table. If the result of the formula is a record, the resulting table contains records with the same columns as the result record.
31
34
32
-
If the result of the formula is a *blank* value, then there will be no record in the result table for that input record. In this case, there will be fewer records in the result table than the source table.
35
+
If the result of the formula is a *blank* value, then there is no record in the result table for that input record. In this case, there will be fewer records in the result table than the source table.
33
36
34
37
### Taking action
38
+
35
39
The formula can include functions that take action, such as modifying the records of a data source with the **[Patch](function-patch.md)** and **[Collect](function-clear-collect-clearcollect.md)** functions. The formula can also call methods on connections. Multiple actions can be performed per record by using the [**;** operator](operators.md). You can't modify the table that is the subject of the **ForAll** function.
36
40
37
-
When writing your formula, keep in mind that records can be processed in any order and, when possible, in parallel. The first record of the table may be processed after the last record. Take care to avoid ordering dependencies. For this reason, you can't use the **[UpdateContext](function-updatecontext.md)**, **[Clear](function-clear-collect-clearcollect.md)**, and **[ClearCollect](function-clear-collect-clearcollect.md)** functions within a **ForAll** function because they could easily be used to hold variables that would be susceptible to this effect. You can use **[Collect](function-clear-collect-clearcollect.md)**, but the order in which records are added is undefined.
41
+
When writing your formula, keep in mind that records can be processed in any order and, when possible, in parallel. The first record of the table may be processed after the last record.
42
+
43
+
Take care to avoid ordering dependencies. For this reason, you can't use the **[UpdateContext](function-updatecontext.md)**, **[Clear](function-clear-collect-clearcollect.md)**, and **[ClearCollect](function-clear-collect-clearcollect.md)** functions within a **ForAll** function because they could easily be used to hold variables that would be susceptible to this effect. You can use **[Collect](function-clear-collect-clearcollect.md)**, but the order in which records are added is undefined.
38
44
39
-
Several functions that modify data sources, including **Collect**, **Remove**, and **Update**, return the changed data source as their return value. These return values can be large and consume significant resources if returned for every record of the **ForAll** table. You may also find that these return values are not what you expect, because **ForAll** can operate in parallel and may separate the side effects of these functions from obtaining their result. Fortunately, if the return value from **ForAll** is not actually used, which is often the case with data modification functions, then the return value will not be created and there are no resource or ordering concerns. But if you are using the result of a **ForAll** and one of the functions that returns a data source, think carefully about how you structure the result and try it out first on small data sets.
45
+
Several functions that modify data sources, including **Collect**, **Remove**, and **Update**, return the changed data source as their return value. These return values can be large and consume significant resources if returned for every record of the **ForAll** table. You may also find that these return values are not what you expect because **ForAll** can operate in parallel and may separate the side effects of these functions from obtaining their result. If the return value from **ForAll** is not used, which is often the case with data modification functions, then the return value will not be created and there are no resource or order concerns. But if you are using the result of a **ForAll** and one of the functions that returns a data source, think carefully about how you structure the result and try it out first on small data sets.
40
46
41
47
### Alternatives
42
-
Many functions in Power Apps can process more than one value at a time through the use of a single-column table. For example, the **Len** function can process a table of text values, returning a table of lengths, in the same manner that **ForAll** could. This can eliminate the need to use **ForAll** in many cases, can be more efficient, and is easier to read.
48
+
Many functions in Power Apps can process more than one value at a time through the use of a single-column table. For example, the **Len** function can process a table of text values, returning a table of lengths, in the same manner, that **ForAll** could. This can eliminate the need to use **ForAll** in many cases, can be more efficient, and is easier to read.
43
49
44
50
Another consideration is that **ForAll** is not delegable while other functions may be, such as **Filter**.
**Formula* - Required. The formula to evaluate for all records of the *Table*.
@@ -58,7 +64,7 @@ The following examples use the **Squares** [data source](../working-with-data-so
58
64
59
65

60
66
61
-
To create this data source as a collection, set the **OnSelect** property of a **Button** control to this formula, open Preview mode, and then click or tap the button:
67
+
To create this data source as a collection, set the **OnSelect** property of a **Button** control to this formula, open Preview mode, and then select the button:
62
68
63
69
`ClearCollect( Squares, [ "1", "4", "9" ] )`
64
70
@@ -72,33 +78,33 @@ The following examples use the **Expressions** [data source](../working-with-dat
72
78
73
79

74
80
75
-
To create this data source as a collection, set the **OnSelect** property of a **Button** control to this formula, open Preview mode, and then click or tap the button:
81
+
To create this data source as a collection, set the **OnSelect** property of a **Button** control to this formula, open Preview mode, and then select the button:
This example also uses a [Microsoft Translator](../connections/connection-microsoft-translator.md) connection. To add this connection to your app, see the topic about how to [manage connections](../add-manage-connections.md).
85
+
This example also uses a [Microsoft Translator](../connections/connection-microsoft-translator.md) connection. To add this connection to your app, see the article about how to [manage connections](../add-manage-connections.md).
80
86
81
87
| Formula | Description | Result |
82
88
| --- | --- | --- |
83
-
|**ForAll(Expressions, MicrosoftTranslator.Translate( Value, "es" ) )**|For all the records in the Expressions table, translate the contents of the **Value** column into Spanish (abbreviated "es"). ||
84
-
|**ForAll(Expressions, MicrosoftTranslator.Translate( Value, "fr" ) )**|For all the records in the Expressions table, translate the contents of the **Value** column into French (abbreviated "fr"). ||
89
+
|**ForAll(Expressions, MicrosoftTranslator.Translate( Value, "es"))**|For all the records in the Expressions table, translate the contents of the **Value** column into Spanish (abbreviated "es"). ||
90
+
|**ForAll(Expressions, MicrosoftTranslator.Translate( Value, "fr"))**|For all the records in the Expressions table, translate the contents of the **Value** column into French (abbreviated "fr"). ||
85
91
86
92
### Copying a table
87
-
Sometimes you need to filter, shape, sort, and manipulate data. Power Apps provides a number of functions for doing this, such as **Filter**, **AddColumns**, and **Sort**. Power Apps treats each table as a value, allowing it to flow through formulas and be consumed easily.
93
+
Sometimes you need to filter, shape, sort, and manipulate data. Power Apps provides many functions for doing this, such as **Filter**, **AddColumns**, and **Sort**. Power Apps treat each table as a value, allowing it to flow through formulas and be consumed easily.
88
94
89
-
And sometime you will want to make a copy of this result for later use. Or you will want to move information from one data source to another. Power Apps provides the **Collect** function to copy data.
95
+
And sometimes you want to make a copy of this result for later use, or you want to move information from one data source to another. Power Apps provides the **Collect** function to copy data.
90
96
91
-
But before you make that copy, think carefully if it is really needed. Many situations can be addressed by filtering and shaping the underlying data source ondemand with a formula. Some of the downsides to making a copy include:
97
+
But before you make that copy, think carefully if it is needed. Many situations can be addressed by filtering and shaping the underlying data source on-demand with a formula. Some of the downsides to making a copy include:
92
98
93
-
* Two copies of the same information means that one of them can fall out of sync.
94
-
* Making a copy can consume a lot of computer memory, network bandwidth, and/or time.
99
+
* Two copies of the same information mean that one of them can fall out of sync.
100
+
* Making a copy can consume much of the computer memory, network bandwidth, and/or time.
95
101
* For most data sources, copying cannot be delegated, limiting how much data can be moved.
96
102
97
103
The following examples use the **Products**[data source](../working-with-data-sources.md):
98
104
99
105

100
106
101
-
To create this data source as a collection, set the **OnSelect** property of a **Button** control to this formula, open Preview mode, and then click or tap the button:
107
+
To create this data source as a collection, set the **OnSelect** property of a **Button** control to this formula, open Preview mode, and then select the button:
102
108
103
109
```powerapps-dot
104
110
ClearCollect( Products,
@@ -134,7 +140,7 @@ ShowColumns(
134
140
135
141
A [record scope](../working-with-tables.md#record-scope) is created by the **Filter** and **AddColumns** functions to perform the comparison and subtraction operations, respectively, with the **'Quantity Requested'** and **'Quantity Available'** fields of each record.
136
142
137
-
In this example, the **Filter** function can be delegated. This is important, as it can find all the products that meet the criteria, even if that is only a few records out of a table of millions. At this time, **ShowColumns** and **AddColumns** cannot be delegated, so the actual number of products that needs to be ordered will be limited. If you know the size of this result will always be relatively small, this approach is fine.
143
+
In this example, the **Filter** function can be delegated. This is important, as it can find all the products that meet the criteria, even if that is only a few records out of a table of millions. At this time, **ShowColumns** and **AddColumns** cannot be delegated, so the actual number of products that need to be ordered will be limited. If you know the size of this result will always be relatively small, this approach is fine.
138
144
139
145
And because we didn't make a copy, there is no additional copy of the information to manage or fall out of date.
140
146
@@ -154,7 +160,7 @@ ForAll( Products,
154
160
155
161
This formula may be simpler for some people to read and write.
156
162
157
-
No part of the **ForAll** is delegable. Only the first portion of the **Products** table will be evaluated, which could be a problem if this table is very large. Because **Filter** could be delegated in the previous example, it could work better with large data sets.
163
+
No part of the **ForAll** is delegable. Only the first portion of the **Products** table will be evaluated, which could be a problem if this table is large. Because **Filter** could be delegated in the previous example, it could work better with large data sets.
158
164
159
165
#### Collect the result
160
166
In some situations, a copy of data may be required. You may need to move information from one data source to another. In this example, orders are placed through a **NewOrder** table on a vendor's system. For high-speed user interactions, you may want to cache a local copy of a table so that there is no server latency.
@@ -187,7 +193,7 @@ ClearCollect( NewOrder,
187
193
)
188
194
```
189
195
190
-
**ClearCollect** and **Collect** can't be delegated. As a result the amount of data that can be moved in this manner is limited.
196
+
**ClearCollect** and **Collect** can't be delegated. As a result, the amount of data that can be moved in this manner is limited.
191
197
192
198
#### Collect within ForAll
193
199
Finally, we can perform the **Collect** directly within the **ForAll**:
@@ -208,5 +214,5 @@ ForAll( Products,
208
214
209
215
Again, the **ForAll** function can't be delegated at this time. If our **Products** table is large, **ForAll** will look at the first set of records only and we may miss some products that need to be ordered. But for tables that we know will remain small, this approach is fine.
210
216
211
-
Note that we are not capturing the result of the **ForAll**. The **Collect** function calls made from within it will return the **NewOrder** data source for all the records, which could add up to a lot of data if we were capturing it.
217
+
Note that we are not capturing the result of the **ForAll**. The **Collect** function calls made from within it will return the **NewOrder** data source for all the records, which could add up to numerous data if we were capturing it.
Copy file name to clipboardExpand all lines: powerapps-docs/maker/canvas-apps/functions/function-sequence.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,12 +50,12 @@ The number of records to generate is rounded down to the nearest whole number an
50
50
51
51
| Formula | Description | Result |
52
52
| --- | --- | --- |
53
-
|**Sequence( 4 )**| Generates a 4 record table starting at the default 1 and incrementing by the default 1. ||
54
-
|**Sequence( 4, 24 )**| Generates a 4 record table starting at 24 and incrementing by the default 1. ||
55
-
|**Sequence( 4, 4, -1 )**| Generates a 4 record table starting at 4 and incrementing by -1, effectively counting backward. ||
56
-
|**Sequence( 4, -100, 0.5 )**| Generates a 4 record table starting at -100 and incrementing by 0.5. ||
57
-
|**Sequence( 0.9 )**| Generates an *empty* table as the count rounds down to 0. ||
58
-
|**ForAll( Sequence( 4 ), Rand() )**| Generates a 4 record table of random numbers. |<br>*Actual numbers will vary.*|
53
+
|**Sequence( 4 )**| Generates a 4 record table starting at the default 1 and incrementing by the default 1. ||
54
+
|**Sequence( 4, 24 )**| Generates a 4 record table starting at 24 and incrementing by the default 1. ||
55
+
|**Sequence( 4, 4, -1 )**| Generates a 4 record table starting at 4 and incrementing by -1, effectively counting backward. ||
56
+
|**Sequence( 4, -100, 0.5 )**| Generates a 4 record table starting at -100 and incrementing by 0.5. ||
57
+
|**Sequence( 0.9 )**| Generates an *empty* table as the count rounds down to 0. ||
58
+
|**ForAll( Sequence( 4 ), Rand() )**| Generates a 4 record table of random numbers. |<br>*Actual numbers will vary.*|
59
59
|**Concat( Sequence( 5 ),<br>Text( Value ) & " " )**| Generates a string of numbers from 1 to 5. |**"1 2 3 4 5 "**|
0 commit comments