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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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

Top Solution Authors