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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
D_Khandelwal
Frequent Visitor

Unable to sort column using "Sort by column" when a filter condition is applied in measure

Hello All, 


I've created a below measure (there are 4-5 switch cases but I've shorten it to one only) which is working fine untill and unless I apply "Sort by column" to sort "attribute" column with the help of another "sort" column once I apply sorting then the value of this measure goes blank, I observed the reason behind this behavious is whenever I remove the filter condition ('Data Table'[Attribute] = "PTD_Actual") from measure and sort it then it will work fine but if I keep the filter condition and then sort it then it goes blank, 

It seems like either filter will work or else sorting will work but I need both here, please see the DAX measure and screenshots for reference below

Without sort - please see highlighted content only

D_Khandelwal_0-1680516425987.png

With sort

D_Khandelwal_1-1680516551957.png

 

Insights =
var dateV = SELECTEDVALUE(calendarDate[AS_ON_DATE])
Var calc = CALCULATE(
    SUM('Data Table'[Value]),
    TCH_TIME_DIM[AS_ON_DATE]=dateV,
    'Data Table'[Attribute] = "PTD_Actual"
)
Var SwitchV =
SWITCH(
    MAX('Data Table'[Attribute]),
    "Daily-Actual",calc
)
return
SwitchV
 
ThankYou so much in advance
Dinky 
1 ACCEPTED SOLUTION

You need the REMOVEFILTERS in the measure definition, 

Insights =
VAR dateV =
    SELECTEDVALUE ( calendarDate[AS_ON_DATE] )
VAR calc =
    CALCULATE (
        SUM ( 'Data Table'[Value] ),
        TCH_TIME_DIM[AS_ON_DATE] = dateV,
        'Data Table'[Attribute] = "PTD_Actual",
        REMOVEFILTERS ( 'Data Table'[Attribute sort] )
    )
VAR SwitchV =
    SWITCH ( MAX ( 'Data Table'[Attribute] ), "Daily-Actual", calc )
RETURN
    SwitchV

View solution in original post

6 REPLIES 6
johnt75
Super User
Super User

Inside the CALCULATE try adding REMOVEFILTERS on the column which you are using to sort by.

Thanks for your response @johnt75 ,

 

For sorting I've tried both power query and DAX, the Dax statement is below and I'm not sure how to use REMOVEFILTERS inside calculate as I didn't used calculate function,

 

Attribute Sort =
SWITCH(
    'Data Table'[Attribute Orig],
    "Daily-Actual",1,
    "Daily-Budget",2,
    "Daily Var.", 3,4
)

 

Could you please explain it more, 

 

Thanks,

Dinky 

You need the REMOVEFILTERS in the measure definition, 

Insights =
VAR dateV =
    SELECTEDVALUE ( calendarDate[AS_ON_DATE] )
VAR calc =
    CALCULATE (
        SUM ( 'Data Table'[Value] ),
        TCH_TIME_DIM[AS_ON_DATE] = dateV,
        'Data Table'[Attribute] = "PTD_Actual",
        REMOVEFILTERS ( 'Data Table'[Attribute sort] )
    )
VAR SwitchV =
    SWITCH ( MAX ( 'Data Table'[Attribute] ), "Daily-Actual", calc )
RETURN
    SwitchV

It worked, Thank you so much @johnt75 

 

Also, if you could share the reason behind this behavious that would be awesome.

Thanks again,

 

Regards,

Dinky

When you set a column to be sorted by another column, any time the first column is used in a visual the sort by column is also added to the DAX query used to generate the data, even if the sort by column doesn't appear visually. This means that for any given data point both the first column and the sort by column are in the filter context. If you wish to manipulate the filter context to remove or change the first column, you need to take care of the sort by column too.

Alright, Got it.
Thanks for your time and solution

 

Regards,

Dinky

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.