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...