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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Switch Statement or IF
Power Apps
Answered

Switch Statement or IF

(0) ShareShare
ReportReport
Posted on by 66

Hello everyone,

 

New to power apps...

I have a gallery that is grouped and sorted:  SortByColumns(GroupBy('2021_PART_C_GRV', "SOURCE_ORG", "REGION", "CONTRACT_NUMBER", "ListResults"), "REGION", Ascending, "CONTRACT_NUMBER", Ascending, "SOURCE_ORG", Ascending)

 

Each of the sorted / grouped rows have 4 rows each for each quarter of the year (1 thru 4) but I only want to see the data grouped by 3 fields.  So this works, I can see the data in the gallery as I like.

 

Next, I have to change the color of each item in the gallery based on if a field is blank or 0.  I can't get that to work with a switch or IF statement.  I tried a sum, I have tried just the field itself, but nothing.  Any thoughts?

 

This is what I started with:  If(Sum(ThisItem.ListResults.OData__x0031_A_TOT_NUM_GRV)=0 || Sum(IsBlank)ThisItem.ListResults.OData__x0031_A_TOT_NUM_GRV) || ,White,Yellow). 

 

Thanks for your help!!

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    Hi @MEGA1 ,

    I am not sure on your logic here, but the below will show yellow if any of the field items are blank or zero.

    If(
     CountRows(
     Filter(
     ThisItem.ListResults,
     OData__x0031_A_TOT_NUM_GRV = 0
     )
     )=0 &&
     CountRows(
     Filter(
     ThisItem.ListResults,
     IsBlank(OData__x0031_A_TOT_NUM_GRV)
     )
     )=0,
     White,
     Yellow
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • MEGA1 Profile Picture
    66 on at

    Thank you for your response @WarrenBelz!  Can you help me understand that statement you helped me with ?  I tried that and it set all of my rows to yellow in the gallery.

     

    My Data looks something like the attached, that's why I was trying to do a Sum.  Each row of data in the gallery that is grouped has 4 rows associated to it, Q1, Q2, Q3 and Q4.  I'm trying to change the color based on whether the data has been populated for the 4 quarters or not.  So, if there is an amount in any of the 4 quarters, then the data population is "Started" - Yellow.  If the 4 quarters are 0 or blank, the data population is "Not Started" - White.

    MEGA1_6-1633966349236.png

     

     

  • MEGA1 Profile Picture
    66 on at

    Ahhh @WarrenBelz, I may see the light!  I think the statement you provided may work, let me play a little more with the data, I just changed the && to || but I'll play with it a bit more.  Otherwise, I may have to play a little more with the Sum.

     

    Thanks!

  • MEGA1 Profile Picture
    66 on at

    @WarrenBelz - not working for what I need.  I may have to do the sum, but that's not working either

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    @MEGA1 ,

    Maybe something like this

    With(
     {
     wList:
     GroupBy(
     '2021_PART_C_GRV', 
     "SOURCE_ORG", 
     "REGION", 
     "CONTRACT_NUMBER", 
     "ListResults"
     )
     },
     If(
     CountRows(
     Filter(
     ListResults,
     YourQuarterField = ThisItem.YourQuarterField
     )
     ) = 
    	 CountRows(
     Filter(
     ListResults,
     YourQuarterField = ThisItem.YourQuarterField &&
     YourTotalField <> 0 
     )
     ),
     White,
     Yellow
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • MEGA1 Profile Picture
    66 on at

    Thank you - the with statement doesn't work for me.  my QUARTER field isn't part of the groupby, it's only part of the ListResults.  I so greatly appreciate your help!!

     

    I tried what you originally sent me and it sort of works but it makes all items in the gallery yellow, so I do have to figure out how to filter it or apply differently.  only the first item in the gallery should be yellow, the others should remain white as they all currently have that number field as blank.

     

    If(
    CountRows(
    Filter(
    ThisItem.ListResults,
    OData__x0031_A_TOT_NUM_GRV = 0
    )
    )=0 &&
    CountRows(
    Filter(
    ThisItem.ListResults,
    IsBlank(OData__x0031_A_TOT_NUM_GRV)
    )
    )=0,
    White,
    Yellow
    )

     

     

    I also tried this but doesn't work:

    If(
    Sum(ThisItem.ListResults, OData__x0031_A_TOT_NUM_GRV)=0 || IsBlank(Sum(OData__x0031_A_TOT_NUM_GRV)),
    White,
    Yellow
    )

    MEGA1_0-1633989262315.png

     

  • WarrenBelz Profile Picture
    154,399 Most Valuable Professional on at

    Hi @MEGA1 ,

    And that is where you are in a blind canyon - you need to not group by your quarter field (so it is then in the nested gallery) and display it in the parent gallery in a Label as First(ListResults).QuarterFieldName

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

  • Verified answer
    MEGA1 Profile Picture
    66 on at

    I'm so silly, my syntax was wrong, this works now - thank you sooooo much for your help!!!!!

     

    If(Sum(ThisItem.ListResults, OData__x0031_A_TOT_NUM_GRV)=0 || IsBlank(Sum(ThisItem.ListResults, OData__x0031_A_TOT_NUM_GRV)),White,Yellow)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 85

#2
WarrenBelz Profile Picture

WarrenBelz 76 Most Valuable Professional

#3
Kalathiya Profile Picture

Kalathiya 38 Super User 2026 Season 1

Last 30 days Overall leaderboard