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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
learner03
Post Partisan
Post Partisan

Double sort in Matrix

How can I sort with the criteria as Arrivl Date Asc to Desc with non-blanks on top an then second sort by Alternate column from Ase to Desc Date.

it is a matrix visual

Arrive dateAlternate
 22/02/2022
 24/02/2022
21/02/202225/02/2022
 21/02/2022
 24/02/2022
24/02/202224/02/2022
23/02/202223/02/2022
 24/02/2022
24/02/202217/02/2022
23/02/202215/02/2022
23/02/202221/02/2022
 23/02/2022
 25/02/2022
17/02/202218/02/2022
18/02/202218/02/2022
24/02/202218/02/2022
 25/02/2022
 25/02/2022
18/02/202221/02/2022
 25/02/2022
 25/02/2022
17/02/202218/02/2022
 25/02/2022

@OwenAuger 

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @learner03 ,

 

According to your description, the best way to sort the reference is as follows: you can create a column and use the result of the rankx function as the index.

Column = IF('Table'[Arrive date]=BLANK(),1,2)
Col_rank = 
RANKX (
    'Table',
    RANKX ( 'Table', 'Table'[Column],, ASC ) * 1000
        + RANKX ( 'Table', 'Table'[Alternate],, DESC, DENSE )
)

vhenrykmstf_0-1646114286301.png


If the problem persists, please point out the specific error and provide a screenshot of the expected results. Looking forward to your feedback.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @learner03 ,

 

According to your description, the best way to sort the reference is as follows: you can create a column and use the result of the rankx function as the index.

Column = IF('Table'[Arrive date]=BLANK(),1,2)
Col_rank = 
RANKX (
    'Table',
    RANKX ( 'Table', 'Table'[Column],, ASC ) * 1000
        + RANKX ( 'Table', 'Table'[Alternate],, DESC, DENSE )
)

vhenrykmstf_0-1646114286301.png


If the problem persists, please point out the specific error and provide a screenshot of the expected results. Looking forward to your feedback.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

OwenAuger
Super User
Super User

Hi @learner03 

In a matrix, nesting is handled automatically, so I would suggest creating sort by columns for these two columns.

 

I wasn't quite clear on the sort order - did you mean that for both columns, the most recent dates should appear first?

 

For such sorting, I would created columns (in Power Query) that are the negative of the original date (possibly with a constant added), but map null values to zero.

e.g. for Arrive date, the sort column could be:

if [Arrive date] = null then 0 else -Number.From([Arrive date])

Then set Arrive date to sort by this column in the model.

Similarly for Alternate.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

@OwenAuger Yes, you understood correctly that I need sorted by recent dates in both but first sort by Arrival date and second by Alternate,

I tried as you said, but whe I sort it, then the 0 is coming at the top

amitchandak
Super User
Super User

@learner03 , Is there an opportunity is fill up or fill down in power Query ?

https://docs.microsoft.com/en-us/power-query/fill-values-column

 

Then we can use stepped layout off

@amitchandak I can't fiill up/down with any dates as the empty ones are based on when the product reaches. So, if we do not know when the product will reach, then it will by empty field.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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