Skip to main content

Notifications

Power Pages - Design & Build
Unanswered

Using Variable as a DataSource

(0) ShareShare
ReportReport
Posted on by 266
Hi,
I would like to use a variable as a datasource in a ForAll loop but cannot work out if this is possible or not.
 
This is what I have so far - I am creating a collection which has the variable value in it that I need to use.
 
The variable needs to be in the FILTER Datasource - below it shows as 'Shipments-FY2024' - it could be 'Shipments-FY2019' 2020, 2021 etc.  Each of the Datasources exist as their own dataverse tables in my app.
 
ClearCollect(
    colDS,
    Filter(
        tblYears,
        IsActive = true
    )
);
Clear(colTest);
ForAll(
    colDS As DataLoop,
    Collect(
        colTest,
        Sort(
            Filter(
                'Shipments-FY2024',
                Solution = "CompanyName"             ),
            NetRevenueUSD,
            SortOrder.Ascending
        )
    )
)
 
I have no errors with the above but the datasource is static - I need it to change for each year.
 
The following gives me a Invalid Data Type which then of course errors on the Solution = "CompanyName" as Solution does not exist.
 
ForAll(
    colDS As DataLoop,
    Collect(
        colTest,
        Sort(
            Filter(
                DataLoop.YearDataSource,
                Solution = "CompanyName"             ),
            NetRevenueUSD,
            SortOrder.Ascending
        )
    )
)
 
I have tried changing the value that is stored in the tblYears e.g. single quotes in the field 'Shipments-FY2024' or just plain Shipments-FY2024.
 
Any hints from anyone on how to make the variable be seen as a dataverse table(datasource) is appreciated.
 
I looked at using SET / UpdateContext but they are not allowed in a ForAll.
 
My current work around is using a Switch for each year - but this will require maintenance for each year.
Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,691

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 65,019

Leaderboard

Featured topics