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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Dyke211
Helper I
Helper I

I want to Rank this Matrix table in a descending manner based on the last month with value

Hi guys, I have a Power BI challenge. I want to rank a Matrix table based on the last month column that contains a value. This means that months with zeros should not be considered for sorting, but instead the most recent month with a non-zero value (in this case, July).

How can I achieve this? Please help.

 

Screenshot 2025-09-12 113730.png

 

1 ACCEPTED SOLUTION

Hi @Dyke211 ,

You don't want to show the (Rankby LastNonZero) in the table. And want to show  just the Months but its should be sorted by july 25.

 

Solution: Drag the "RankByLastNonZero" measure into the Values field temporarily .

Click the Matrix visual  --> open the visual header menu (three dots ...)  --> Sort by --> choose "RankByLastNonZero"  and set Descending. After the rows are sorted correctly, remove "RankByLastNonZero" from the Values. The visual remembers the sort and will stay sorted by that measure.

 

While "RankByLastNonZero" field in values  , refer snap.

 

vdineshya_0-1757944919858.png

 

while sorting the measure in descending order, refer snap.

 

vdineshya_1-1757945106053.png

 

vdineshya_2-1757945170273.png

 

Please refer below output result before removing "RankByLastNonZero" field in Values.

vdineshya_3-1757945226478.png

 

Please refer below output result , After removing "RankByLastNonZero" field in Values.

 

vdineshya_4-1757945319915.png

 

Note: Their is no change in final output after removing "RankByLastNonZero" field in Values. Now you can't see the "RankByLastNonZero" in Matrix visual.

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

View solution in original post

8 REPLIES 8
v-dineshya
Community Support
Community Support

Hi @Dyke211 ,

Thank you for reaching out to the Microsoft Community Forum.

 

You  want to rank a Matrix table based on the last month column that contains a value., means that months with zeros should not be considered for sorting, but instead the most recent month with a non-zero value (in this case, July).

 

Please refer below output snap and attached PBIX file.

 

vdineshya_0-1757685050974.png

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

Thanks for this, looks close but in a case where I want to sort by month in July based on rank but dont want rank column like (Rankby LastNonZero) to show in the table . WHat should show is just the Months but its should be sorted by july 25

Hi @Dyke211 ,

You don't want to show the (Rankby LastNonZero) in the table. And want to show  just the Months but its should be sorted by july 25.

 

Solution: Drag the "RankByLastNonZero" measure into the Values field temporarily .

Click the Matrix visual  --> open the visual header menu (three dots ...)  --> Sort by --> choose "RankByLastNonZero"  and set Descending. After the rows are sorted correctly, remove "RankByLastNonZero" from the Values. The visual remembers the sort and will stay sorted by that measure.

 

While "RankByLastNonZero" field in values  , refer snap.

 

vdineshya_0-1757944919858.png

 

while sorting the measure in descending order, refer snap.

 

vdineshya_1-1757945106053.png

 

vdineshya_2-1757945170273.png

 

Please refer below output result before removing "RankByLastNonZero" field in Values.

vdineshya_3-1757945226478.png

 

Please refer below output result , After removing "RankByLastNonZero" field in Values.

 

vdineshya_4-1757945319915.png

 

Note: Their is no change in final output after removing "RankByLastNonZero" field in Values. Now you can't see the "RankByLastNonZero" in Matrix visual.

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

Hi @Dyke211  ,

I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. Weโ€™re always here to support you.

Best Regards, 
Community Support Team 

Hi @Dyke211 ,

We havenโ€™t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

 

Regards,

Dinesh

Hi @Dyke211 ,

We havenโ€™t heard from you on the last response and was just checking back to see if you have a resolution yet. And, if you have any further query do let us know.

 

Regards,

Dinesh

Hoangechip910
Frequent Visitor

hi

First need to define which month is ranked

+Need a extra index column (1,2,3,4,...) correcsond to Months Order, you will filter which months have SUM (values) > 0, then find Max of Index Number.

Second do Ranking

Filter your table which month you found in first, then rank, use function RANKX.

DId not work

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.