Group expression examples in paginated reports (Power BI Report Builder)
APPLIES TO: Power BI Report Builder Power BI Desktop
In a data region in a paginated report, you can group data by a single field, or create more complex expressions that identify the data on which to group. Complex expressions include references to multiple fields or parameters, conditional statements, or custom code. When you define a group for a data region, you add these expressions to the Group properties. For more information, see Add or Delete a Group in a Data Region (Report Builder and SSRS).
To merge two or more groups that are based on simple field expressions, add each field to the group expressions list in the group definition.
Examples of Group Expressions
The following table provides examples of group expressions that you can use to define a group.
Description | Expression |
---|---|
Group by the Region field. |
=Fields!Region.Value |
Group by last name and first name. | =Fields!LastName.Value =Fields!FirstName.Value |
Group by the first letter of the last name. | =Fields!LastName.Value.Substring(0,1) |
Group by parameter, based on user selection. In this example, the parameter GroupBy must be based on an available values list that provides a valid choice to group on. |
=Fields(Parameters!GroupBy.Value).Value |
Group by three separate age ranges: "Under 21", "Between 21 and 50", and "Over 50". |
=IIF(First(Fields!Age.Value)<21,"Under 21",(IIF(First(Fields!Age.Value)>=21 AND First(Fields!Age.Value)<=50,"Between 21 and 50","Over 50"))) |
Group by many age ranges. This example shows custom code written in Visual Basic .NET that returns a string for the following ranges: 25 or Under 26 to 50 51 to 75 Over 75 |
=Code.GetRangeValueByAge(Fields!Age.Value) Custom code: Function GetRangeValueByAge(ByVal age As Integer) As String Select Case age Case 0 To 25 GetRangeValueByByAge = "25 or Under" Case 26 To 50 GetRangeValueByByAge = "26 to 50" Case 51 to 75 GetRangeValueByByAge = "51 to 75" Case Else GetRangeValueByByAge = "Over 75" End Select Return GetRangeValueByByAge End Function |