cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ap7
Level: Powered On

Trouble Using a Switch and If Statement Together

I'm having trouble using the Switch and If statements together and hoping someone can help. I have a text field that is populated with data from a SP list called 'Hours Cross Charged' and the column name varies based on the month selected (thus the switch statement--shown below).

 

Switch(
SelectedMonth,
"January", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)=Text(ProjectName_1), 'January Notes'),
"February", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)=Text(ProjectName_1), 'February Notes'),
"March", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)=Text(ProjectName_1), 'March Notes')
)

 

However, some of these fields will be blank, and those are returning the text "false." In order to remove that text and have them populated with nothing, or just hint text, I've been attempting to use an IF statement after this Switch statement. But PowerApps is finding an error at the semicolon that I put after the Switch statement's closing parenthesis there, regardless of how I'm formatting my If. 

 

Switch(
SelectedMonth,
"January", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)=Text(ProjectName_1), 'January Notes'),
"February", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)=Text(ProjectName_1), 'February Notes'),
"March", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)=Text(ProjectName_1), 'March Notes')
);
If(
IsBlank(TextInput_Notes.Text), " ", " ")

Surely it's something simple that I'm overcomplicating... does anyone have any suggestions on how to combine these two?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Trouble Using a Switch and If Statement Together

You can use the Coalesce function that will replace the blank value with the value that you want:

Coalesce(
    Switch(
        SelectedMonth,
        "January", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)= Text(ProjectName_1), 'January Notes'),
        "February", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value) = Text(ProjectName_1), 'February Notes'),
        "March", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value) = Text(ProjectName_1), 'March Notes')
    ),
    "")

Hope this helps!

View solution in original post

2 REPLIES 2
Highlighted
Power Apps Staff CarlosFigueira
Power Apps Staff

Re: Trouble Using a Switch and If Statement Together

You can use the Coalesce function that will replace the blank value with the value that you want:

Coalesce(
    Switch(
        SelectedMonth,
        "January", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value)= Text(ProjectName_1), 'January Notes'),
        "February", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value) = Text(ProjectName_1), 'February Notes'),
        "March", LookUp('Hours Cross Charged', Name=User().FullName && Text(Project.Value) = Text(ProjectName_1), 'March Notes')
    ),
    "")

Hope this helps!

View solution in original post

ap7
Level: Powered On

Re: Trouble Using a Switch and If Statement Together

Oh my gosh, how did I miss that? Thank you so much @CarlosFigueira 

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,202)