'How to get record before and after in forall loop powerapps
I am trying to run a function that returns a table with a corresponding date index and date text. This is so that I can display the information in a tutorial screen. However, I am confused on how to access to the previous record. Here is my pseudocode:
ForAll( Tweets (sorted by crf1d_date_index),
If(the record IS NOT the LAST record,
If('crf1d_date_index' != 'crf1d_date_index' of the NEXT record,
{
Step: crf1d_date_index,
Text: crf1d_tweet_time
}
)
)
If(the record IS the LAST record,
If('crf1d_date_index' != 'crf1d_date_index' of the PREVIOUS record),
{
Step: crf1d_date_index,
Text: crf1d_tweet_time
}
)
)
Solution 1:[1]
You can use the Sequence function to create a list of indices, and then use that list within ForAll to access your list of tweets, something along the lines of the expression below:
With(
{ myTweets, Tweets(sorted by crf1d_date_index) },
ForAll(
Sequence(CountRows(myTweets)),
With(
{
tweet: Index(myTweets, Value),
previousTweet: If(Value > 1, Index(myTweets, Value - 1)),
nextTweet: If(Value < CountRows(myTweets), Index(myTweets, Value + 1))
},
If(
Value < CountRows(myTweets),
If(
tweet.'crf1d_date_index' != nextTweet.'crf1d_date_index',
{ Step: crf1d_date_index, Text: crf1d_tweet_time }
),
If(
tweet.'crf1d_date_index' != previousTweet.'crf1d_date_index',
{ Step: crf1d_date_index, Text: crf1d_tweet_time }
)
)
)
)
)
Solution 2:[2]
Set(distinctTweets, AddColumns(
GroupBy(Tweets, "crf1d_date_index", "Dates"),
"tweet_time",
First(Dates).tweet_time));
With({myTweets:SortByColumns(distinctTweets,"crf1d_date_index")},
ForAll(Sequence(CountRows(myTweets)),
With({tweet:Index(myTweets,Value)},
If(true,
{
Step:Value-1,
Text: tweet.tweet_time,
Image: SampleImage
}, Blank()
)
)
)
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chris Schaller |
| Solution 2 | Jonathan |
