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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jr3151006
Helper IV
Helper IV

How can I add the 'ORDER BY' inside that current DAX in a way to SORT ASC?

Hi,

 

I have a measure which get the dates filtered in a 'DateDimension' table, but as you can see on the imagem below, the order of months are not in the right order.

Q: What is the right 'position' to insert the DAX 'ORDER BY' with 'ASC' parameter?

 

 

MeasureSelectedPeriods = 
IF (
ISFILTERED ( 'DateDimension' ),
CONCATENATEX (
VALUES ( DateDimension[Month-Year]  ), DateDimension[Month-Year], ", " ), "No period selected" )

 

 


########################
Current result obtained
######################## 
DAX-SelectedPeriods-not-ordered.png





########################
The desired/expected would be:
########################
DAX-SelectedPeriods-diresired-order.png

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @jr3151006 ,

I created some data:

vyangliumsft_0-1670811275353.png

Here are the steps you can follow:

1. Create calculated column.

Year_Month =
MONTH('Table'[Date]) &"/"&YEAR('Table'[Date])

2. Create measure.

Measure =
var _min=MINX(ALLSELECTED('Table'),[Date])
var _max=MAXX(ALLSELECTED('Table'),[Date])
var _table=
FILTER(
    'Table','Table'[Date]>=_min&&'Table'[Date]<=_max)
var _table1=
SUMMARIZE(_table,[Year_Month])
return
CONCATENATEX(_table1,[Year_Month],",")

3. Result:

vyangliumsft_1-1670811275356.png

 

Best Regards,

Liu Yang

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

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @jr3151006 ,

I created some data:

vyangliumsft_0-1670811275353.png

Here are the steps you can follow:

1. Create calculated column.

Year_Month =
MONTH('Table'[Date]) &"/"&YEAR('Table'[Date])

2. Create measure.

Measure =
var _min=MINX(ALLSELECTED('Table'),[Date])
var _max=MAXX(ALLSELECTED('Table'),[Date])
var _table=
FILTER(
    'Table','Table'[Date]>=_min&&'Table'[Date]<=_max)
var _table1=
SUMMARIZE(_table,[Year_Month])
return
CONCATENATEX(_table1,[Year_Month],",")

3. Result:

vyangliumsft_1-1670811275356.png

 

Best Regards,

Liu Yang

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

Greg_Deckler
Super User
Super User

@jr3151006 If those aren't real dates but text, it is going to sort them as if they are text. Perhaps try adding a Sort By column with a real date?


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi,

are you talking about to apply order directly on the table field??

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors