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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
M_K_T
New Member

DAX query with date parameter

Using Report Builder, I created a dataset that contains a date parameter. I need to add an order by to the DAX Query but am unsure of the correct syntax. Example is below. I need to order by 'Task'[ActivityDate] DESC

 

DEFINE VAR vFromTaskActivityDateHierarchy1 = IF(PATHLENGTH(@FromTaskActivityDateHierarchy) = 1, IF(@FromTaskActivityDateHierarchy <> "", @FromTaskActivityDateHierarchy, BLANK()), IF(PATHITEM(@FromTaskActivityDateHierarchy, 2) <> "", PATHITEM(@FromTaskActivityDateHierarchy, 2), BLANK()))
VAR vFromTaskActivityDateHierarchy1ALL = PATHLENGTH(@FromTaskActivityDateHierarchy) > 1 && PATHITEM(@FromTaskActivityDateHierarchy, 1, 1) < 1
VAR vToTaskActivityDateHierarchy1 = IF(PATHLENGTH(@ToTaskActivityDateHierarchy) = 1, IF(@ToTaskActivityDateHierarchy <> "", @ToTaskActivityDateHierarchy, BLANK()), IF(PATHITEM(@ToTaskActivityDateHierarchy, 2) <> "", PATHITEM(@ToTaskActivityDateHierarchy, 2), BLANK()))
VAR vToTaskActivityDateHierarchy1ALL = PATHLENGTH(@ToTaskActivityDateHierarchy) > 1 && PATHITEM(@ToTaskActivityDateHierarchy, 1, 1) < 1
EVALUATE SUMMARIZECOLUMNS('Task'[WhatId], 'Task'[Status], 'Task'[Description], 'Task'[ActivityDate], FILTER(VALUES('Task'[ActivityDate]), (vFromTaskActivityDateHierarchy1ALL || 'Task'[ActivityDate] >= DATEVALUE(vFromTaskActivityDateHierarchy1) + TIMEVALUE(vFromTaskActivityDateHierarchy1)) && (vToTaskActivityDateHierarchy1ALL || 'Task'[ActivityDate] <= DATEVALUE(vToTaskActivityDateHierarchy1) + TIMEVALUE(vToTaskActivityDateHierarchy1))))

 

Any assistance is appreciated. 

2 REPLIES 2
Anonymous
Not applicable

Hi @M_K_T ,

Have you solved the current problem?

Best Regards,

Xianda Tang

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

Anonymous
Not applicable

Hi @M_K_T ,

To do this. you can use the clause ORDER BYORDER BY in a DAX query. which allows you to specify the columns to be sorted and the direction of the sort

EVALUATE 
SUMMARIZECOLUMNS(
    'Task'[WhatId], 
    'Task'[Status], 
    'Task'[Description], 
    'Task'[ActivityDate], 
    FILTER(
        VALUES('Task'[ActivityDate]), 
        (vFromTaskActivityDateHierarchy1ALL || 'Task'[ActivityDate] >= DATEVALUE(vFromTaskActivityDateHierarchy1) + TIMEVALUE(vFromTaskActivityDateHierarchy1)) && 
        (vToTaskActivityDateHierarchy1ALL || 'Task'[ActivityDate] <= DATEVALUE(vToTaskActivityDateHierarchy1) + TIMEVALUE(vToTaskActivityDateHierarchy1))
    )
)
ORDER BY 'Task'[ActivityDate] DESC

Best Regards,

Xianda Tang

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

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

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