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
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (66,868)