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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Switch Statement for a...
Power Apps
Unanswered

Switch Statement for a collection value giving error

(1) ShareShare
ReportReport
Posted on by 16
I got a Dataverse table "Expenses" with columns like 2022,2023,2024 (whole number) for each year and like ExpenseType, Department etc.
 
I want to get the value of Sum for each year in a variable to be used in a label according to the Year selected in dropdown. The following is the code selected for a record in the table with a combination of various dropdown selections.
 
UpdateContext({vYear:Left(Text(comboBoxTitle.Selected.Title),4)}) ;   
 
(The above works Fine gives year 2022,2023,2024 etc. )   
 
ClearCollect(colSpend, AddColumns(GroupBy(Filter(colExpense, Department="Operation"),ExpenseType,Group),   
Sum2022,Sum(Group,2022),
Sum2023,Sum(Group,2023),
Sum2024,Sum(Group,2024)
));
 
(above works fine gives columns Sum2022, Sum2023, Sum2024 values like 3000, 4000, 2000 in colSpend. colExpense is already a collection made from Expenses table columns)   
 
UpdateContext({vFinal: Switch(vYear,
"2022", Wants to put the value pf Sum2022(giving error )
"2023", Wants to put the value pf Sum2023(giving error)
"2024",Wants to put the value pf Sum2024(giving error)));
 
How to put the value of the Sum for variable in the Switch column to avoid the error that name is not valid "Sum2022" etc...
 
Categories:
I have the same question (0)
  • CU25101055-0 Profile Picture
    16 on at
    This is resolved by 
    UpdateContext({vFinal: Switch(vYear,
    "2022", First(colSpend.Sum2022)
    "2023", First(colSpend.Sum2023)
    "2024",First(colSpend.Sum2024))});
     
    The Switch function is not giving any error now and vFinal is picking the right values.
     
    Thanks a lot for accepting this question in the forum.
  • CU25101055-0 Profile Picture
    16 on at
    Sorry I inadvertently misplaced Parenthesis location inmy last post for the solution :
     
    It was resolved with:
    UpdateContext({vFinal: Switch(vYear,
    "2022", First(colSpend).Sum2022
    "2023", First(colSpend).Sum2023
    "2024",First(colSpend).Sum2024)});
     
    The above worked fine. 

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

Forum hierarchy changes are complete!

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

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard