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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
afbraga66
Helper III
Helper III

Sort Matrix by dynamic column value based on filters

Hi,

 

I have a requirement to sort a matrix by the last possible month value, 7 in the example below. The issue is that Power BI only sorts by the total and that is not what I want.

 

afbraga66_0-1626465715337.png

 

I want it to look like the image below, i.e. sorted by the values where month equals 7, because it is the latest with the filters I have.

afbraga66_1-1626465715769.png

 

I did it with this formula:

 

Today Month = CALCULATE([mDuration(min)], KEEPFILTERS(DOWNTIME[MES_FABRIL]=MONTH(TODAY())))

 

The problem is that it is fixed to todays month, and I can't have it like that. I want it to have the dynamic filtering according to if I select 1 month, 2 months or none. If I select 5 and 6, then 6 should be the one being used for sorting since it is the latest. If I don't select anything then it is 7. Can you please help me making it dynamic?

Check the pbix file with the example above. PBI Test example 

 

Thank you.

 

Best regards,

André

11 REPLIES 11
Vmpbi
Frequent Visitor

Thanks for sharing… check out the links below. It provides a comprehensive guide on how to sort measures as columns 

in a matrix visual. 

https://insurancedatainsights.blog/2024/04/27/dynamic-data-display-matrix/ 

https://www.youtube.com/watch?v=k5FMfvPmkv4&t=190s 

Anonymous
Not applicable

Hi @afbraga66 ,

 

It's not supported to sort the matrix by specific column.

You could vote for this idea.

https://ideas.powerbi.com/ideas/idea/?ideaid=05c64cd1-c0d0-44d3-bceb-21f4acc0e548 

 

Best Regards,

Jay

afbraga66
Helper III
Helper III

Sorry to bother @Greg_Deckler , but add any luck with it? Thank you for helping me!

 

Best regards,

André

afbraga66
Helper III
Helper III

Hey@Greg_Deckler , is it possible to do that? Thank you 🙂

Greg_Deckler
Community Champion
Community Champion

@afbraga66 So like this?:

Today Month = 
    VAR __Date = MAX('DOWNTIME'[DIA_FABRIL])
RETURN
    CALCULATE([mDuration(min)], KEEPFILTERS(DOWNTIME[MES_FABRIL]=MONTH(__Date)))

Updated PBIX attached below sig.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hello Greg,

 

Thank you so much for your help.

I tried your formula, but I have a issue with it. It's the fact that when the value is null it assumes in the total the latest value for the given months(148,05 from month 6). But in this case I need the 81 to be before the null in the sorting. Is there another way?

afbraga66_0-1626682864541.png

 

Best regards,

André

@afbraga66 Perhaps:

Today Month = 
    VAR __Date = MAX('DOWNTIME'[DIA_FABRIL])
RETURN
    IF(ISBLANK([mDuration (min)],
      BLANK(),
      CALCULATE([mDuration(min)], KEEPFILTERS(DOWNTIME[MES_FABRIL]=MONTH(__Date)))
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hey @Greg_Deckler ,

 

I have tried it, but it is not working. Still giving the same result as the previous one unfortunately.

Probably because the ISBLANK() evaluates against the values of all months in that expression?

Thank you.

@afbraga66 What about this version?

Today Month = 
    VAR __Date = MAX('DOWNTIME'[DIA_FABRIL])
    VAR __mDuration = CALCULATE([mDuration(min)],KEEPFILTERS(DOWNTIME[MES_FABRIL]=MONTH(__Date)))
RETURN
    IF(ISBLANK(__mDuration),
      BLANK(),
      __mDuration
    )


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hey @Greg_Deckler ,

Sorry to bother but any news on this topic?

Hey @Greg_Deckler ,

 

Same result unfortunately 😞

afbraga66_0-1626793842130.png

 

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.