How to Group Power BI Matrix Rows by Code While Keeping Name Above Code
Question details
The user needs to group rows in a Power BI matrix by a shared code while keeping a name above the code and displaying the preferred name for each code.

- Product
- Microsoft Power BI
- Device & OS
- not provided
- Scenario
- Building or editing a Power BI report matrix in which multiple names map to the same code and the visual must show one preferred name per code.
- Observed behavior
- The matrix should group all rows that share a Code under the preferred Name and display Name above Code in the row hierarchy.
Open your Power BI Desktop report and confirm that the source table contains both a Code column and a Name column. Decide which Name should be preferred when a Code has multiple name values.
Create a preferred-name helper column and use it in the matrix row hierarchy
Use this method when you need to override alternate Name values and group all matrix rows by Code while still showing Name above Code.
Power BI groups matrix rows by the exact fields placed in the Rows bucket. If you place the original Name field first, shared codes can split into separate groups. A helper column that returns one preferred Name per Code gives the matrix a stable top-level row field.
In Power BI Desktop, select the Data view icon on the left side, then choose the table that contains the Code and Name columns.
On the Table tools tab, click New column, name it Preferred Name, and enter a DAX formula that returns the preferred Name for each Code, such as the first valid Name for that Code.
Select the matrix visual, go to the Visualizations pane, and drag Preferred Name into Rows above Code to create a Name > Code hierarchy.
Expand the matrix and confirm that all rows with the same Code appear together under the preferred Name and alternate names are no longer shown as row headers.

Use WPS Office to prepare Power BI source data with a free Office alternative
Power BI Desktop is a Microsoft reporting tool, and WPS Office does not modify Power BI visuals. For the spreadsheet and source-data work around your Power BI reports, WPS Office is a free, lightweight, easy-to-use Microsoft Office alternative with familiar ribbons and strong format compatibility.
- 1. Download WPS Office Free: Visit the official WPS Office website and download the free installer for your Windows PC, Mac, or mobile device.
- 2. Open your source data: Launch WPS Office, open the Excel or CSV file that feeds Power BI, and review the Code and Name columns used in your matrix.
- 3. Edit in a familiar interface: Use WPS Spreadsheets to clean, filter, and organize the data before refreshing the Power BI report.

Frequently Asked Questions
Can I group a Power BI matrix by Code without creating a calculated column?
The matrix groups by the exact field values placed in Rows. If multiple Name values share the same Code, Power BI may create separate row groups unless you add a helper or calculated column that returns one preferred Name per Code.
Which DAX function should I use to return the first valid Name for each Code?
It depends on the data and business rule. Common options include FIRSTNONBLANK, TOPN, MIN, MAX, or CALCULATE with FILTER and ALLEXCEPT. In Power BI Desktop, use Table tools > New column and test the formula in Data view.
Does WPS Office include Power BI Desktop?
No, WPS Office does not include Power BI Desktop. You can use WPS Spreadsheets to prepare Excel or CSV source data, then open that data in Power BI Desktop for report building.
Will the matrix still show Code under Name?
Yes. Place the Preferred Name helper column first and Code second in the Rows bucket to create a Name > Code drilldown hierarchy, so Code is shown under the preferred Name.




