cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DavidMCoeo
Regular Visitor

Conditional GroupBy

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")
			
2 REPLIES 2
Meneghino
Community Champion
Community Champion

Hi @DavidMCoeo

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.

mr-dang
Community Champion
Community Champion

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.

Microsoft Employee
@8bitclassroom

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,464)