Switch Function in Query Expression (1 Viewer)

Drand

Registered User.
Local time
Today, 15:52
Joined
Jun 8, 2019
Messages
179
Hi All

I am trying to use the switch function in a query.

The function I have created is:

YTDBud: Switch(Month(Date())=1,[sumofJan]),(Month(Date()) =2,[sumofJan]+[SumofFeb]

Where SumofJan and SumofFeb are fields in the query.

YTDBud: Switch(Month(Date())=1 returns the correct value for SumofJan but when I add the second expression I get an error message

"the expression you entered contains invalid sysntax,or you need to enclose your text data in quotes"

Is it possible to use the switch function the way I am attempting, and if so, what is the issue with my syntax?

Really appreciate your assistance.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:52
Joined
Oct 29, 2018
Messages
21,467
You need to move the closing parens to the very end.

From ... [sumofJan]),

To ... + [SomOfFeb])

Hope that helps...
 

Drand

Registered User.
Local time
Today, 15:52
Joined
Jun 8, 2019
Messages
179
Thanks both for your responses. Both of which will work as I need it.

I was not aware of the choose function. This is far simpler than what I was attempting.

Again, many thanks
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:52
Joined
Oct 29, 2018
Messages
21,467
Thanks both for your responses. Both of which will work as I need it.

I was not aware of the choose function. This is far simpler than what I was attempting.

Again, many thanks
Glad we could assist. Good luck with your project.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:52
Joined
May 7, 2009
Messages
19,230
For info, the Switch function cannot be used in a query unless it is used within a wrapper function.
i think this is wrong info. You can of course use Switch() inside a Query. Maybe you have mistaken it with Split function.
 

isladogs

MVP / VIP
Local time
Today, 06:52
Joined
Jan 14, 2017
Messages
18,212
Oops. I need new glasses. I did indeed mean the Split function. Thanks
 

Users who are viewing this thread

Top Bottom