Forum Discussion
How to add a Serial Row Number Column in Power BI Table / Matrix visual?
- 9 years ago
Hi ShmuelM,
Grabbing in your table just add a measure with the countrows:
Row_Number = CALCULATE ( COUNTROWS(Profit_Table), FILTER ( ALLSELECTED ( Profit_Table ), Profit_Table[Position] <= MAX ( Profit_Table[Position]) ) )As you can see in the print below it counts the number of rows no matter if you have slicer or not, left table is the full data, right table is influenced by slicer.
Please be aware that this measure is influenced by the order of your Position so if you want to order by another column this will give you the row number in a different order also.
Regards,
MFelix
Hi Anonymous ,
This depends on the context can you share some mockup data?
Sure!
So I have the following Matrix:
I need to add one row, at the beggining of the matrix, with the row number: 1,2,3,4,5,6 .....
I have tried it your way and it just gives random numbers that i can't include in the matri. The closest I have been to achieving my goal was this expression:
- MFelix4 years agoSuper User
Hi Anonymous ,
Has you refer you cannot add a measure except on the values part of your matrix, meaning that you cannot use it in the rows.
In order to do this maybe you can use a disconnected table with the order and then make a measure using the ranking and the disconnected table, one question is your ranking based on the total value of the matrix? so the last column that refers to the total GRP20?
- Anonymous4 years agoNot applicable
Hi again hehe
I am not sure of what you mean...I am quite new to Power Bi... I do can tell you that in fact, the table has to be ordered by that column, GRP20, so I guess the ranking should be done having that under consideration? I dont know x) I am so lost here...
- MFelix4 years agoSuper User
Hi Anonymous ,
For this you need to do the following:
- Add a disconnected table with the values of ranking 1 to 20 (or more if you need) this can be added using an what if parameter
- Then create the following measures:
Ranking sales = CALCULATE( RANKX(ALL( Table[Column of the Rows in matrix]), calculate([Measure])), ,desc), ALLSELECTED(Table[Column of the Columns in matrix]))Values for matrix = IF(HASONEVALUE(Table[Column of rows in matrix]), IF(SELECTEDVALUE(ranking[ranking]) = [Ranking sales], [Measure]), [Measure])- Now setup your matrix in the following way:
- Rows:
- Ranking
- Column you need
- Columns:
- Column you need
- Values:
- Measure Values for matrix
- Turn of step layout and drill down to the lowest level
- Rows:
Has you can see below the matrix on top that has the ranking is matching the one on the bottom that is only sorted by the total values:
The data is from the Adventure works database.
If you need any PBIX file with example please tell me and I can try and share one.