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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
vividarinda
Helper II
Helper II

Sort Latest Week Value

Hi All,

How to sort the latest week values from the matrix below? 

vividarinda_1-1721793006284.png

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @vividarinda ,

 

(1)We can create a date table.

Date = ADDCOLUMNS(CALENDAR(DATE(2024,1,1),DATE(2024,12,31)),"week",WEEKNUM([Date]))

(2)We can create a column and a measure.

ExtractedNumber = 
VAR FirstSpace = SEARCH(" ", 'Table'[Week], 1)
VAR SecondSpace = SEARCH(" ", 'Table'[Week], FirstSpace + 1)
RETURN MID('Table'[Week], FirstSpace + 1, SecondSpace - FirstSpace - 1)
Measure = var _max=MAXX(ALLSELECTED('Date'),[week])
var _filter=MAXX(FILTER(ALLSELECTED('Table'),[Description] in VALUES('Table'[Description])&&[ExtractedNumber]=_max),[value])
return _filter

(3)Creating Model Relationship.

vtangjiemsft_0-1721976288705.png

(4)Sort - Turn off text wrap - Manually adjust column width to hide.

vtangjiemsft_1-1721976343425.png

vtangjiemsft_2-1721976478995.png

Best Regards,

Neeko Tang

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

Anonymous
Not applicable

Hi @vividarinda ,

 

We can create a date table.

Date = ADDCOLUMNS(CALENDAR(DATE(2024,1,1),DATE(2024,12,31)),"week",WEEKNUM([Date]),"month",MONTH([Date]))

This is my test data. We can create columns.

vtangjiemsft_0-1722219255835.png

_month = 
LEFT([month], FIND(" ", [month]) - 1)
_month_num = MONTH( CONVERT([_month]&" "&1,DATETIME))

We can create a measure.

Measure 2 = 
var _max=MAXX(ALLSELECTED('Date'),[month])
var _filter=MAXX(FILTER(ALLSELECTED('Table (2)'),[Description] in VALUES('Table (2)'[Description])&&[_month_num]=_max),[value])
return _filter

vtangjiemsft_1-1722219315912.png

 

If you still have problems following up, please create a new case, we suggest a case to solve only one problem, because it can get good help and give a better reference for other users!

 

Best Regards,

Neeko Tang

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

8 REPLIES 8
Anonymous
Not applicable

Hi @vividarinda ,

 

First of all thanks to @Joe_Barry  for the quick reply. I have some other thoughts to add:

(1)This is my test data.

vtangjiemsft_0-1721887637575.png

(2) We can create columns.

ExtractedNumber = 
VAR FirstSpace = SEARCH(" ", 'Table'[Week], 1)
VAR SecondSpace = SEARCH(" ", 'Table'[Week], FirstSpace + 1)
RETURN MID('Table'[Week], FirstSpace + 1, SecondSpace - FirstSpace - 1)
RANK = 
var _max= MAX('Table'[ExtractedNumber])
var _rank=RANKX(FILTER('Table',[ExtractedNumber]=EARLIER('Table'[ExtractedNumber])),[value],,DESC)
RETURN IF([ExtractedNumber]=_max,_rank,BLANK())

(3)Place the rank columns on the matrix visual object, set sorting by ascending order of the rank columns, and then manually adjust the column widths to hide the rank columns while turning off [text wrap] for the column headers.

vtangjiemsft_3-1721888298969.pngvtangjiemsft_4-1721888334185.png

Best Regards,

Neeko Tang

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

Hi @Anonymous ,

Thank you for the quick response. However, my current situation involves using a date filter, where the data retrieved is the latest 4 weeks based on the filter date and sorting the values in ascending order based on the selected week. As an example, if I filter from April 27th to May 26th, the visualization will only display data from the last 2 weeks out of the 4 weeks included in the filter

vividarinda_2-1721893356589.png

 

 

vividarinda_1-1721893327449.png

 

Anonymous
Not applicable

Hi @vividarinda ,

 

(1)We can create a date table.

Date = ADDCOLUMNS(CALENDAR(DATE(2024,1,1),DATE(2024,12,31)),"week",WEEKNUM([Date]))

(2)We can create a column and a measure.

ExtractedNumber = 
VAR FirstSpace = SEARCH(" ", 'Table'[Week], 1)
VAR SecondSpace = SEARCH(" ", 'Table'[Week], FirstSpace + 1)
RETURN MID('Table'[Week], FirstSpace + 1, SecondSpace - FirstSpace - 1)
Measure = var _max=MAXX(ALLSELECTED('Date'),[week])
var _filter=MAXX(FILTER(ALLSELECTED('Table'),[Description] in VALUES('Table'[Description])&&[ExtractedNumber]=_max),[value])
return _filter

(3)Creating Model Relationship.

vtangjiemsft_0-1721976288705.png

(4)Sort - Turn off text wrap - Manually adjust column width to hide.

vtangjiemsft_1-1721976343425.png

vtangjiemsft_2-1721976478995.png

Best Regards,

Neeko Tang

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

Hi @Anonymous ,

Thank you for your quick response. Your suggestion is amazing—I’ve already applied the logic for weekly tasks. However, I encountered an issue when trying to apply the same logic for monthly tasks. See the image below:

vividarinda_0-1722213661780.png

 

Anonymous
Not applicable

Hi @vividarinda ,

 

We can create a date table.

Date = ADDCOLUMNS(CALENDAR(DATE(2024,1,1),DATE(2024,12,31)),"week",WEEKNUM([Date]),"month",MONTH([Date]))

This is my test data. We can create columns.

vtangjiemsft_0-1722219255835.png

_month = 
LEFT([month], FIND(" ", [month]) - 1)
_month_num = MONTH( CONVERT([_month]&" "&1,DATETIME))

We can create a measure.

Measure 2 = 
var _max=MAXX(ALLSELECTED('Date'),[month])
var _filter=MAXX(FILTER(ALLSELECTED('Table (2)'),[Description] in VALUES('Table (2)'[Description])&&[_month_num]=_max),[value])
return _filter

vtangjiemsft_1-1722219315912.png

 

If you still have problems following up, please create a new case, we suggest a case to solve only one problem, because it can get good help and give a better reference for other users!

 

Best Regards,

Neeko Tang

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

 

Hi @Anonymous ,

Thanks, I really appreciate your support. Next, I will address a separate issue in a different context.

vividarinda
Helper II
Helper II

Hi @Joe_Barry ,

Thanks for your reply. My expectation result like this. Sort the values in descending order starting from last week : 134, 127, 127, etc

vividarinda_0-1721807250298.png

 

Joe_Barry
Super User
Super User

Hi @vividarinda 

 

  • Do you have a column in your table called week number? If you don't you can create one in Power Query. Highlight the Week column
  • Go to the ribbion and choose Add Column > Extract > Extract after delimiter.
  • In the field hit your space bar and presss ok.
  • A new column withe a number will be created convert to Whole number if needed.
  • Load the table.
  • Go to the Table View and highlight the old Week column
  • Go to the ribbion > Column tools > Sort by column and choose the new column
  • The visual can now be sorted correctly. You can choose additional sort options if you hover over the top right of the visual

Joe




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Learn about the Star Schema, it will solve many issues in Power BI!

Date tables help! Learn more



LinkedIn


Let's connect on LinkedIn


Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors