2

I have built a weather app in Power Apps. I'm using the MSN weather connector to gather several basic criteria, namely "Precipitation". So I have several images I'd like to use for sunny, cloudy, and rainy days. I have a field that I set called "currentPrecip" which I want to change the image based on. This line successfully gives me a gif called "mostly-cloudy" when currentPrecip equals one of these 3 phrases:

If(currentPrecip = "Mostly cloudy" Or "Cloudy" Or "Partly cloudy", 'mostly-cloudy', sunnygif)

Currently, if the currentPrecip is anything else, the image switches to a sunny gif. But I'd like to also include parameters for Sunny and Rainy days. Basically what I'm after is:

  1. If currentPrecip = "Mostly Cloudy" Or "Cloudy" Or "Partly cloudy" - Display 'mostly-cloudy' gif
  2. If current Precip = "Rainy", "Rain", "Thunderstorms", "Light drizzle" - Display 'rainy-gif' gif
  3. If currentPrecip = "Sunny" Or "Clear" - Display 'sunnygif' gif.

I keep getting syntax errors when trying to write this, so any help would be appreciated.

2 Answers 2

3

You have to nest the If statements. What that does is, if the criteria for the first condition evaluates to false, instead of having a value for a false result, you have another If statement to evaluate.

If (
    currentPrecip = "Mostly Cloudy" Or "Cloudy" Or "Partly cloudy",
    'mostly-cloudy',
    If (
        currentPrecip = "Rainy" Or "Rain" Or "Thunderstorms" Or "Light drizzle",
        'rainy-gif',
        If (
            currentPrecip = "Sunny" Or "Clear",
            'sunnygif',
            Blank()
        )
    )
)

You could also make it a little simpler by eliminating the last If statement:

If (
    currentPrecip = "Mostly Cloudy" Or "Cloudy" Or "Partly cloudy",
    'mostly-cloudy',
    If (
        currentPrecip = "Rainy" Or "Rain" Or "Thunderstorms" Or "Light drizzle",
        'rainy-gif',
        'sunnygif'
    )
)
1
  • This is perfect. Thank you for laying that out for me! Looks like it's working...just have to wait for a precipitation change.
    – Chris
    Commented Jun 3, 2022 at 16:55
0

If function in Power Apps supports chaining of multiple "Conditions" & "ThenResults" as given in below syntax:

If( Condition1, ThenResult1 [, Condition2, ThenResult2, ... [ , DefaultResult ] ] )

Documentation: If and Switch functions in Power Apps


So, for your requirements you can use the formula in simplest way like:

If (
    currentPrecip = "Mostly Cloudy" Or currentPrecip = "Cloudy" Or currentPrecip = "Partly cloudy",
    'mostly-cloudy',
    currentPrecip = "Rainy" Or currentPrecip = "Rain" Or currentPrecip = "Thunderstorms" Or currentPrecip = "Light drizzle",
    'rainy-gif',
    'sunnygif'
)

Use this formula in Image property of Image control.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.