ave a corresponding
outer value to help define the current row on which to operate, with the
following behavior:

  * If there is exactly one corresponding outer column, its value is used. 
  * If there is no corresponding outer column, then: 
    * ROWNUMBER will first determine all <orderBy>, <partitionBy>, and <matchBy> columns that have no corresponding outer column. 
    * For every combination of existing values for these columns in ROWNUMBER parent context, ROWNUMBER is evaluated and a row is returned. 
    * ROWNUMBERâs final output is a union of these rows. 
  * If there is more than one corresponding outer column, an error is returned. 

If <matchBy> is present, then ROWNUMBER will try to use columns in <matchBy>
and <partitionBy> to idenfity the current row.  
If the columns specified within <orderBy> and <partitionBy> cannot uniquely
identify every row in <relation>, then:

  * ROWNUMBER will try to find the least number of additional columns required to uniquely identify every row. 
  * If such columns can be found, ROWNUMBER will 
    * Try to find the least number of additional columns required to uniquely identify every row. 
    * Automatically append these new columns to <orderBy> clause. 
    * Sort each partition using this new set of orderBy columns. 
  * If such columns cannot be found and the function detects a tie at runtime, an error is returned. 

<reset> can be used in visual calculations only, and cannot be used in
combination with <orderBy> or <partitionBy>. If <reset> is present, <axis> can
be specified but <relation> cannot.

##  Example 1 - calculated column

The following DAX query:

    
    
    EVALUATE
    ADDCOLUMNS(
        'DimGeography',
        "UniqueRank",
        ROWNUMBER(
        	'DimGeography',
        	ORDERBY(
        		'DimGeography'[StateProvinceName], desc,
        		'DimGeography'[City], asc),
        	PARTITIONBY(
        		'DimGeography'[EnglishCountryRegionName])))
    ORDER BY [EnglishCountryRegionName] asc, [StateProvinceName] desc, [City] asc
    

Returns a table that uniquely ranks each geography with the same
EnglishCountryRegionName, by their StateProvinceName and City.

##  Example 2 - visual calculation

The following visual calculation DAX queries:

    
    
    SalesRankWithinYear = ROWNUMBER(ORDERBY([SalesAmount], DESC), PARTITIONBY([CalendarYear]))
    
    SalesRankAllHistory = ROWNUMBER(ORDERBY([SalesAmount], DESC))
    

Create two columns that uniquely rank each month by the total sales, both
within each year, and the entire history.

The screenshot below shows the visual matrix and the first visual calculation
expression:

![DAX visual calculation](media/dax-queries/dax-visualcalc-rownumber.png)

##  Related content

[ INDEX ](index-function-dax)  
[ ORDERBY ](orderby-function-dax)  
[ PARTITIONBY ](partitionby-function-dax)  
[ WINDOW ](window-function-dax)  
[ RANK ](rank-function-dax)

* * *

##  Feedback

Was this page helpful?

Yes  No

##  Feedback

Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the
feedback mechanism for content and replacing it with a new feedback system.
For more information see: [ https://aka.ms/ContentUserFeedback
](https://aka.ms/ContentUserFeedback) .

Submit and view feedback for

This page

[ View all page feedback  ](https://github.com//issues)

* * *

##  Additional resources

[ California Consumer Privacy Act (CCPA) Opt-Out Icon  Your Privacy Choices
](https://aka.ms/yourcaliforniaprivacychoices)

Theme

  * Light 
  * Dark 
  * High contrast 

  *   * [ Previous Versions ](/en-us/previous-versions/)
  * [ Blog ](https://techcommunity.microsoft.com/t5/microsoft-learn-blog/bg-p/MicrosoftLearnBlog)
  * [ Contribute ](/en-us/contribute/)
  * [ Privacy ](https://go.microsoft.com/fwlink/?LinkId=521839)
  * [ Terms of Use ](/en-us/legal/termsofuse)
  * [ Trademarks ](https://www.microsoft.com/legal/intellectualproperty/Trademarks/)
  * © Microsoft 2024 

##  Additional resources

###  In this articl