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
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 330 members 6,586 guests
Please welcome our newest community members: