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
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 69 members 3,530 guests
Please welcome our newest community members: