cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DavidMCoeo
Level: Powered On

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
Level 10

Re: Conditional GroupBy

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
Level 10

Re: Conditional GroupBy

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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (10,315)