Skip to main content

Notifications

Power Platform Community / Forums / Design & Build / Using Variable as a Da...
Design & Build
Unanswered

Using Variable as a DataSource

Posted on by 258
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:

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Community Update Sept 16…

Power Platform Community Update…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 140,719

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,355

Leaderboard

Featured topics