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 / Conditional GroupBy
Power Apps
Unanswered

Conditional GroupBy

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Is there a way to dynamically set the fields that a dataset is grouped by in a GroupBy funtion?

 

I'm trying to do it with an If() as with limited sucess

 

If(
		cbGroupClient.Value = false && cbGroupMonth.Value = true
			,GroupBy('Renewable Book Test',"Month","Customer_Group")
		,cbGroupClient.Value = true && cbGroupMonth.Value = false
			,GroupBy('Renewable Book Test',"Customer","Customer_Group")
		,cbGroupClient.Value = true && cbGroupMonth.Value = true
			,GroupBy('Renewable Book Test',"Month", "Customer" ,"Customer_Group")
			
Categories:
I have the same question (0)
  • Meneghino Profile Picture
    6,949 on at

    Hi @Anonymous

    What do you mean by 'limited success'? What is the issue?

    Thanks.

     

    PS There does not seem to be anything obviously wrong with your formula, although the syntax could be shortened.  Also, there seems to be no result in case both Client and Month are false, which could be throwing PowerApps.

  • Brian Dang Profile Picture
    3,976 on at

    I think I understand the problem with setting a condition for GroupBy. The function is meant to be used to nest one Gallery into another: the child Gallery is set to the result of GroupBy. 

     

    Gallery1.Items:
    GroupBy(datasource,"column1","grouped_column1")

    Gallery2.Items:
    grouped_column1

    If Gallery2 relies on having grouped_column1 as the Item, then it will fail to populate data if grouped_column1 does not exist.

     

    As an alternative, I would recommend using AddColumns to add a new temporary column that pulls in data from the column you want for GroupBy based on your conditions. Then use GroupBy on that temporary column:

    GroupBy(
    	
    	AddColumns(
    		'Renewable Book Test',
    		"tempcolumn",[put your conditions here]
    	),
    	
    	"tempcolumn","Customer_Group"
    )

    You can set the child Gallery to 

    Customer_Group

    and it would be consistent no matter the condition.

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 387

#2
timl Profile Picture

timl 340 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 301

Last 30 days Overall leaderboard