cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MEGA1
Helper I
Helper I

Switch Statement or IF

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

1 ACCEPTED SOLUTION

Accepted Solutions
MEGA1
Helper I
Helper I

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)

View solution in original post

8 REPLIES 8
WarrenBelz
Super User
Super User

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.

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

 

 

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
Helper I
Helper I

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

@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
Helper I
Helper I

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

 

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.

MEGA1
Helper I
Helper I

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)

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,738)