Forum Discussion

Charline_74's avatar
Charline_74
Icon for Resolver I rankResolver I
2 years ago
Solved

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

  • 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's avatar
    manvishah17
    Icon for Solution Supplier rankSolution Supplier

    Hi Charline_74 ,
    Using Power Query Editor:

    1. Open Power Query Editor: Go to Home > Transform data.
    2. Add Index Column: Select the table, then Add Column > Index Column > Choose From 0 or From 1.
    3. Apply Changes: Click Close & Apply.
    4. Use Index: Drag the index column into your visual table.

    Using DAX:

    1. Create Calculated Column: Go to Modeling > New Column, and use:
      Index = RANKX(ALL('YourTable'), 'YourTable'[ColumnToOrderBy], , ASC, Dense)
    2. Use Index: Add the new index column to your visual table.
  • 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)