1

I have a list where I group rows and use aggregate() to count specific columns. The issue I'm facing is that the resulting column names all show as "Total Value," which makes it difficult to differentiate between them.

I would like each aggregated column to have a unique name in group header. For example, I want to rename the columns after aggregation based on their purpose or source.

The internal names of the columns I’m working with are:

  • ITBreached
  • BusinessBreached
  • TeamBreached

How can I customize the output column names so that they reflect the specific data they represent, instead of all being labelled the same?

enter image description here

Here’s a simplified version of my current code:

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json", "groupProps": { "hideFooter": false, "headerFormatter": { "elmType": "div", "style": { "display": "flex", "flex-direction": "column", "box-sizing": "border-box", "padding": "4px 8px", "border-radius": "6px", "overflow": "hidden", "margin": "1px 4px 4px 1px" }, "children": [ { "elmType": "div", "style": { "display": "flex", "align-items": "left", "margin-bottom": "5px", "color": "red" }, "children": [ { "elmType": "span", "style": { "max-width": "24px", "max-height": "24px", "margin-left": "8px" } }, { "elmType": "div", "children": [ { "elmType": "div", "txtContent": "= '(Order Count: ' + @group.count + ')'", "style": { "font-weight": "500", "padding": "4px" } } ] }, { "elmType": "div", "children": [ { "elmType": "div", "txtContent": "= @group.fieldData.displayValue", "style": { "font-weight": "500", "padding": "4px" } } ] } ] }, { "elmType": "div", "style": { "display": "flex", "align-items": "center" }, "children": [ { "forEach": "currentValue in @aggregates", "elmType": "div", "txtContent": "= '(Total value: ' + [$currentValue.value] + ')'", "style": { "display": "inline-flex", "margin-right": "8px" } } ] } ] } } } 

1 Answer 1

0

The @aggregates object in SharePoint JSON view formatting has the following properties (with example value), and can be iterated on using for Formatting forEach property:

[ { "value": "3", "columnDisplayName": "Approved", "type": "Count" }, { "value": "1.2", "columnDisplayName": "Growth", "type": "Average" }, { "value": "0.33%", "columnDisplayName": "Rate of change", "type": "Variance" } ] 

So, you can get the name of your column using columnDisplayName property.

For example:

{ "forEach": "currentValue in @aggregates", "elmType": "div", "txtContent": "= '(Total value of ' + [$currentValue.columnDisplayName] + ': ' + [$currentValue.value] + ')'", "style": { "display": "inline-flex", "margin-right": "8px" } } 
2
  • This works and the names are displayed. I have one question if i want to refer to a specific column, without using foreach how can i get the value? Example :out of three i want only the value of 'Approved' in the header to be shown? @Ganesh Sanap - MVP Commented Jan 28 at 6:38
  • For showing specific column, you will have to use the condition in display property (for element under forEach loop). Something like: "display": "=if([$currentValue.columnDisplayName] == 'Approved', 'inline-flex', 'none')". Commented Jan 28 at 10:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.