Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Power BI Table Row Numbers: A Step-by-Step Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Power BI tables work differently from Excel: a table visual does not have row numbers you can switch on, so you have to create a column that counts rows yourself. The most reliable route is to build a row-number column in Power Query with Add Column > Index Column, which gives each row a stable number when the query refreshes. If you need numbers that respond to filters in a report (for example, renumbering the top 10 products after slicing by region), use a DAX measure with RANKX or COUNTROWS instead. The table visual itself has no built-in numbering option in any version.

What You'll Need

  • Power BI Desktop installed, with a report or data model open, or a saved .pbix file.
  • Your data loaded in the Power Query Editor or already in the model.
  • Basic familiarity with Power Query (the Transform Data window) and, for the DAX approach, a working date or category column.
  • Decision made about which kind of number you want: a fixed number in the data (query column) or a number that changes with slicers (DAX measure).

Step-by-Step

  1. Pick your approach first. A column number is stored with the data, counts every row in the table, and is the same for all report users. A DAX number is calculated in the report, respects the filter context (slicers, page filters) and is the right choice when you need a rank within a filtered list. They behave differently, so decide before building.
  2. Open Power Query. In Power BI Desktop, click Transform Data in the ribbon. On the Home tab, click Advanced Editor if you prefer code, but the easiest way is to click your query in the left navigation pane so its steps appear on the right.
  3. Add the index column. With your query selected, open Add Column > Index Column. The dropdown next to the button offers From 0, From 1 and Custom. Choose From 1 for a standard row number, or Custom to set the starting value and increment. To number by group, use Add Column > Index Column after first grouping, or add an index and then group and count.
  4. Check the order before you rely on the number. The Index Column is applied to the rows in the order the query has arranged them at that point. Click the column you want to sort by (for example Date) and sort ascending or descending, then add the index. Do the sort step before the index step, not after.
  5. Rename and type the column. Double-click the new column header and name it Row Number. Right-click the header and confirm the data type is Whole Number. This avoids odd behaviour when you sort by it later.
  6. Apply the changes. Click Close & Apply on the Home tab. The query loads back to the model and the new column appears in the Fields pane.
  7. Add it to a table visual. Select a blank area, then from the Fields pane drag the Row Number column into the table. Power BI sorts table columns by default on the value you click; click the Row Number header to sort ascending.
  8. For a filter-aware number, create a DAX measure. Go to the Home tab, click New Measure , and write a formula such as . This produces a rank within the products currently visible after slicers, and it renumbers when filters change.
  9. If you simply want a count of visible rows, use Row Count = COUNTROWS('Sales') in a measure, or a card visual to show the total number of rows returned by the current filter.
  10. Verify the result. Compare the maximum row number in your table against the row count of the source query. They should match. If they do not, check for duplicate rows, an applied filter in the query, or a wrong starting index.

Note that menu labels can differ slightly by version, device or region; the wording above matches the desktop app's ribbon, and Power BI Desktop has no mobile row-numbering option because report design happens on desktop. You can view the report on mobile, but you cannot edit the model there.

Common Mistakes

  • Adding the index before sorting. The index then numbers whatever arbitrary order the query happened to have, so row 1 might not be the newest or oldest record.
  • Expecting the index to renumber on refresh. A query index is fixed by the query's order at refresh time, but if underlying rows change or the query is re-ordered, previously stable numbers can shift. Do not use it as a permanent ID.
  • Using a DAX measure as a row number in a table that is not sorted by it. A rank measure can look wrong if the visual is sorted by another column; the value is still correct, it just does not appear in sequence.
  • Filtering the table afterwards. Filtering a table visual removes rows, so the numbers will have gaps (1, 4, 7...). That is expected; use RANKX with ALLSELECTED if you need continuous numbers under filters.
  • Forgetting to check the data type. A text-typed index will sort as 1, 10, 100... instead of numerically.

Tips

  • To number rows within groups (for example, per customer), group by the key in Power Query, add an index inside the group, or use a RANKX measure over the customer's transactions.
  • Keep a sort key column alongside the index so the table visual can sort logically without losing the row numbering idea.
  • For simple counting and export to Excel, a query index survives well because it is a real column that exports with the data.
  • Use DENSE ranks in RANKX if you want no gaps when there are ties in the values being ranked.

Troubleshooting

  • The column is missing in the model. Re-open Transform Data and check that the Index step is present after the sort step. Then click Close & Apply again.
  • Numbers restart or duplicate. There may be a group-by step in the query resetting the row order. Move the index step below all sorting and grouping, or use a custom index.
  • The measure returns blanks. Check the table name and column name in the DAX formula and make sure the measure is in a table that has rows in the current filter context.
  • The table visual keeps sorting by another column. Click the Row Number header once; the sort arrow should appear on that column. Filters can then change row contents but not the sort key.
  • Still stuck? Close and reopen the .pbix file, then confirm the query loads without errors in the Power Query Editor. A red error banner there will stop the column appearing.

Frequently Asked Questions

Does a Power BI table have a built-in row number option?

No. The table visual has no numbering setting, so you create a column in Power Query or a DAX measure that produces the number.

Can I number rows in a matrix visual?

Not directly. A matrix groups and aggregates values; use a measure with RANKX to show a rank on each row within its group, or use a table visual instead.

Will the row number update when I refresh the data?

A query index is recalculated at refresh based on the query's current order, so numbers can change if rows are added, removed or re-sorted. It is not a stable identifier.

How do I get continuous numbers even when a filter hides rows?

Use a DAX measure based on RANKX with ALLSELECTED, which ranks only the rows currently in scope and renumbers them.

Can I start numbering from 0 instead of 1?

Yes. In Power Query choose Index Column > From 0, or in the custom option set the starting value.