Forum Discussion
matrix rows order
- 8 months ago
Hi FZOU,
Power BI matrix visual is designed for parent child hierarchies so it repeats the parent (Region) for each child (Store) when you swap them...So here is a couple of solutions Should work try it:
First Approach:In this approach you will create a custom display column that controls the exact order of stores and regions
- Create a Sorting Index Column:
SortIndex = VAR CurrentStore = [Store] VAR CurrentRegion = [Region] VAR StoreRank = RANKX( FILTER(ALL('Stores'), [Region] = CurrentRegion), [Store], , ASC, DENSE ) RETURN StoreRank * 1000 -- Stores get values like 1000, 2000, 3000- Then Create Display Column:
StoreRegionDisplay = VAR CurrentStore = [Store] VAR CurrentRegion = [Region] VAR IsRegionRow = [Store] = [Region] -- Assuming you have region rows in table RETURN IF( IsRegionRow, UPPER(CurrentRegion), -- Region in uppercase CurrentStore -- Store as normal )Also Create Region Sort Column:
RegionSort = VAR CurrentRegion = [Region] VAR RegionNumber = SWITCH( CurrentRegion, "FRANCE", 1, "EMEA", 2, "CHINA", 3, "ARANI", 4, 99 ) RETURN RegionNumber- Finally Create Final Sorting Column:
FinalSort = [RegionSort] * 10000 + [SortIndex]Note:
Sort StoreRegionDisplay by FinalSort
- Use StoreRegionDisplay in matrix rows
Second Approach:Here we will use measures to dynamically display stores and regions
- Just Create a Store List Measure:
StoreList = VAR StoresInContext = VALUES('Stores'[Store]) VAR CurrentRegion = SELECTEDVALUE('Stores'[Region]) VAR StoreCount = COUNTROWS(StoresInContext) RETURN IF( StoreCount = 1, SELECTEDVALUE('Stores'[Store]), CurrentRegion & " - " & FORMAT(StoreCount, "0") & " stores" )Then Use It in Matrix
Rows: Store field
- Add this measure to get smart display
Bonus Approach:
We will Just create Unpivot table then use it in your Custome Visual
Create unpivoted table:
DisplayTable = UNION( SELECTCOLUMNS( FILTER('Stores', [Store] <> [Region]), "DisplayType", "Store", "DisplayValue", [Store], "Region", [Region], "SortOrder", 1 ), SELECTCOLUMNS( 'Stores', "DisplayType", "Region", "DisplayValue", [Region], "Region", [Region], "SortOrder", 2 ) )- Then use it in custom visual or table
if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.
FZOU ,
Power BI’s Matrix visual enforces a hierarchical drill down structure and always places parent categories above child categories. Reversing the hierarchy causes the parent to repeat for each child row. The visual does not support placing a parent category below its children.