Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DavidWest
New Member

Rank Quarterly Sales Across Multiple Years

I have a transaction table with entries for sales events going back many years.

 

I can create a table showing total sales by year and each year's ranking (SalesRank = rankx(all(Transactions[Date].[year]),[SalesTotal],,DESC,Dense)) which functions as expected, showing total sales by year with each year ranked 1, 2, 3, etc.

 

If I add quarter from the date heirarchy to this table the ranking changes to the rank of each Q1 compared to the other Q1s, and each Q2 compared to the other Q2s.  I want it to show the rank of a specific quarter to ALL other quarters (so if I had 4 years of data, it would rank the quarters 1-16).  

 

This is what I get:

 

YearQuarter SalesRank
20222 $          455,5181
20233 $          403,7661
20231 $          318,7941
20224 $          217,5551
20221 $          300,7012
20232 $          268,2922
20223 $          261,5842
20214 $          180,7792
20213 $          234,0853
20204 $          168,4933
20212 $          161,9363
20211 $          143,4693
20202 $          127,6984
20201 $          111,5554
20203 $          102,3454

 

This is what I want:

 

YearQuarter SalesRank
20222 $  455,5181
20233 $  403,7662
20231 $  318,7943
20221 $  300,7014
20232 $  268,2925
20223 $  261,5846
20213 $  234,0857
20224 $  217,5558
20214 $  180,7799
20204 $  168,49310
20212 $  161,93611
20211 $  143,46912
20202 $  127,69813
20201 $  111,55514
20203 $  102,34515

 

I tried using a different measure for changing year to quarter (SalesRankQ = rankx(all(Transactions[Date].[Quarter]),[SalesTotal],,DESC) but every quarter comes back with a ranking of "1."

 

Note - I don't have a Date table.  Since the data heirarchy is already there I haven't had a need to create one (and when I did and linked it to my transaction table it messed up most of my existing reports).

 

Any help is appreciated!

 

 

 

 

 

 

2 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

hi @DavidWest ,

 

not sure if i fully get you, supposing you have data table like:

Date Sales
1/1/2022 1
4/1/2022 2
7/1/2022 3
10/1/2022 4
1/1/2023 9
4/1/2023 8
7/1/2023 7
10/1/2023 6

 

try to

1) add a calculated column like:

qtr = FORMAT ( [Date], "YYYY" ) & "Q" & FORMAT ( [Date], "Q" )

 

2) plot a table visual with qtr column, sales column and a measure like:

rank = 
RANKX(
    ALLSELECTED(data[qtr]),
    CALCULATE(SUM(data[sales]))
)

 

it worked like:

FreemanZ_0-1699588682789.png

 

 

View solution in original post

Thanks!

 

I did: Qtr = FORMAT ( [Date], "YYYY" ) & "Q" & FORMAT ( [Date], "Q" )

 

Your ranking didn't work for me, but using your Qtr calculation I got this to work: 

 

SalesRankQ = rankx(all(Transactions[Qtr]),[SalesTotal],,DESC)
 
I really appreciate your help (and the sample file you provided was invaluable).

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @DavidWest ,

 

not sure if i fully get you, supposing you have data table like:

Date Sales
1/1/2022 1
4/1/2022 2
7/1/2022 3
10/1/2022 4
1/1/2023 9
4/1/2023 8
7/1/2023 7
10/1/2023 6

 

try to

1) add a calculated column like:

qtr = FORMAT ( [Date], "YYYY" ) & "Q" & FORMAT ( [Date], "Q" )

 

2) plot a table visual with qtr column, sales column and a measure like:

rank = 
RANKX(
    ALLSELECTED(data[qtr]),
    CALCULATE(SUM(data[sales]))
)

 

it worked like:

FreemanZ_0-1699588682789.png

 

 

Thanks!

 

I did: Qtr = FORMAT ( [Date], "YYYY" ) & "Q" & FORMAT ( [Date], "Q" )

 

Your ranking didn't work for me, but using your Qtr calculation I got this to work: 

 

SalesRankQ = rankx(all(Transactions[Qtr]),[SalesTotal],,DESC)
 
I really appreciate your help (and the sample file you provided was invaluable).

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.