web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Answered

AddColumns within Switch function

(0) ShareShare
ReportReport
Posted on by 353

Hi,

 

I am having difficulties with integrating 'AddColumns' into formula with 'Switch' function. I want to search the gallery based on two columns, where one is a lookup column, other is of text type. Depending on which column I select from a combobox, I should be able to search the gallery. This search should also have additional logical tests with dates ('Filter' function).

 

Data source is Dataverse table named 'Opportunity'.

One column is 'Account' and that one is a lookup column for which I add 'AddColumns' function.

Another column is 'Opportunity' and that one is text column.

 

When used outside 'Switch' function, this formula works just fine.

 

// This works
Search(AddColumns(Opportunities, "AccountName", Account.'Account Name'), txtSearchBox.Value, "AccountName", "ppt_opprotunityname")

 

 

This is how it looks like in the application:

sdedic_0-1643712352118.png

 

Here is the complete formula with 'Switch' function where I can search the gallery based on the "Opportunity" and filter the gallery based on "Date", but I don't get any results for "Account",

 

Sort(Switch(varSelectedFilter, "Opportunity", Search(Opportunities, txtSearchOpportunity.Value, "ppt_opprotunityname"), "Account", Search(AddColumns(Opportunities, "AccountName", Account.'Account Name'), txtSearchAccount.Value, "AccountName"), "Date", Filter(Opportunities, And('Start Date' >= pckStartDate.Value, 'End Date' <= pckEnddate.Value))), 'Start Date', Ascending)

 

 

varSelectedFilter = selected item from combobox, that is Account, Opportunity or Date.

 

Please let me know if any additional explanation is necessary.

Any advice is appreciated. Ty.

I have the same question (0)
  • v-xiaochen-msft Profile Picture
    on at
    Re: AddColumns within Switch function

    Hi @sdedic ,

     

    Your formula has no syntax or logic problems.

    What's txtSearchAccount?

    Did txtSearchAccount.Value return a correct value?

     

    Best Regards,

    Wearsky

  • Verified answer
    ar87 Profile Picture
    353 on at
    Re: AddColumns within Switch function

    Hi @v-xiaochen-msft,


    Thank you for the reply. My team and I eventually found the solution to this and instead of using 'Switch' we utilized 'Search' and 'StartsWith' functions. 

     

    "Your formula has no syntax or logic problems."

    The formula provided in the previous post didn't show any syntax errors, and worked perfectly fine for "Date" and "Opportunity", but somehow didn't want to filter results for "Account".

     

    'Switch' function was also limiting us to select only one of these three: "Account", "Opportunity", "Date" as filter option.

    What we did, we allowed user to multi-select and do the search with combining filters:

    sdedic_0-1643878926821.png

     

    The formula that worked here (p.s. we also figured out we don't need 'AddColumns' since we created relation with the Account table):

    Search(
     Filter(Opportunities,
     StartsWith(
     Account.'Account Name',
     txtSearchAccount.Value
     ),
     ('Start Date' >= pckStartDate.Value || IsBlank(pckStartDate.Value)) && ('End Date' <= pckEnddate.Value || IsBlank(pckEnddate.Value))
     ),
     txtSearchOpportunity.Value,
     "ppt_name"
    )

     

    "What's txtSearchAccount?"

    txtSearchOpportunity and txtSearchAccount are text input controls.

    pckStartDate and pckEndDate are date picker controls.

     

    "Did txtSearchAccount.Value return a correct value?"

    This was returning correct value only when used outside 'Switch' within 'Search' function.

    // This works
    Search(AddColumns(Opportunities, "AccountName", Account.'Account Name'), txtSearchBox.Value, "AccountName", "ppt_opprotunityname")

     

    This can be marked as resolved. Ty.

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

Coming soon: forum hierarchy changes

In our never-ending quest to improve we are simplifying the forum hierarchy…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 803 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 314 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 253 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics