I am trying to create a Power Query which will sum up certain rows of data based on a condition set by a parameter that is passed to query. Here is the source data:

Profits Sales Sales Region

1 333 North
23 4 West
4 33 East
5 5 West
5 5 North
3 325 East
2 833 East

If the parameter is set to sum by sales region, I’d like the results to look like this:

Sales Region Profits Sales
North 6 338
West 28 9
East 9 1191

If parameter is not set to sum by sales region, the results would look like this:

Profits Sales Sales Region

1 333 North
23 4 West
4 33 East
5 5 West
5 5 North
3 325 East
2 833 East

Basically, and If "yes" then group certain rows of data, if no, do nothing.