Forum Discussion
Having an index column in a visual table
Hi
On my Power BI report, I have a visual table that fetches columns from several tables.
And I'd like to create an index in this visual but I don't know how to do it?
Does anyone have a solution?
Best regards
Charline_74 , You can create a column or measure using RANKX function
For calculated column
Index = RANKX(ALL('Sales'), 'Sales'[OrderDate], , ASC, DENSE)
For measure
IndexMeasure =
VAR CurrentRow = MAX('Sales'[OrderDate])
RETURN
RANKX(ALL('Sales'), 'Sales'[OrderDate], CurrentRow, ASC, DENSE)
6 Replies
- shafiz_p
Super User
Hi, Charline_74 If you don't have column with unique values, and have multiple columns in the table, then you can use rownumber function to create index column with a combination of all the columns in your table. For example,
Index =ROWNUMBER(ALLSELECTED('Table'[Column1], 'Table'[Column2], 'Table'[Column3], 'Table'[Column4]))
Basically Dax don't have any exact function to create index column. You must need to have a column with unique values first then using RANKX function you are able to create index.
It is always better to create index column in power query editor.
Hope this helps!!
If this solved your problem, please mark it as a solution!! - manvishah17
Solution Supplier
Hi Charline_74 ,
Using Power Query Editor:- Open Power Query Editor: Go to Home > Transform data.
- Add Index Column: Select the table, then Add Column > Index Column > Choose From 0 or From 1.
- Apply Changes: Click Close & Apply.
- Use Index: Drag the index column into your visual table.
Using DAX:
- Create Calculated Column: Go to Modeling > New Column, and use:Index = RANKX(ALL('YourTable'), 'YourTable'[ColumnToOrderBy], , ASC, Dense)
- Use Index: Add the new index column to your visual table.
- bhanu_gautam
Super User
Charline_74 , You can create a column or measure using RANKX function
For calculated column
Index = RANKX(ALL('Sales'), 'Sales'[OrderDate], , ASC, DENSE)
For measure
IndexMeasure =
VAR CurrentRow = MAX('Sales'[OrderDate])
RETURN
RANKX(ALL('Sales'), 'Sales'[OrderDate], CurrentRow, ASC, DENSE) - Charline_74
Resolver I
bhanu_gautam & manvishah17
how do I do this when none of my columns contains unique data?Here's the result I got :
- bhanu_gautam
Super User
You can merge two column using concat and create some unique values if possible in your table
- Charline_74
Resolver I
bhanu_gautam : I don't have that option