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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Zuzana
Regular Visitor

MAX value in direct query mode

Hi, 

 

I'm really struggling to find solution for a longer time now. I went through all the advices here, but non of them is working to me. 

 

I'm working in Direct query mode and found some solutions to this already, but nothing is working as I need. 

I have one measure already, which is still not showing the highest category number in every row per child ID: 

Zuzana_0-1745417902668.png

 

#Max Cat = 

VAR ctl = SELECTEDVALUE([child ID])
VAR dupl = FILTER(ALLSELECTED([table]),[child ID]=ctl)

RETURN
MAXX(table, table[category number] )

 

I'd need the table look like this: 

Zuzana_1-1745417938165.png

 

1 ACCEPTED SOLUTION
DataNinja777
Super User
Super User

Hi @Zuzana ,

 

In Direct Query mode, if you're trying to show the maximum category number for each child ID across all related parent ID rows, your current DAX measure isn't correctly removing the row-level filter context. To achieve the desired result—where each row displays the same maximum category number per child ID—you should revise the measure to explicitly remove filters on everything except the child ID. You can use the ALLEXCEPT function to achieve this. Here's the corrected measure:

#Max Cat =
CALCULATE(
    MAX('your_table'[category number]),
    ALLEXCEPT('your_table', 'your_table'[child ID])
)

This version ensures that the measure returns the same maximum value of category number for all rows sharing the same child ID, regardless of other filters in the table. Just replace 'your_table' with the actual name of your table. This approach works in Direct Query mode and avoids the pitfalls of SELECTEDVALUE not resolving correctly due to row context limitations.

 

Best regards,

View solution in original post

2 REPLIES 2
DataNinja777
Super User
Super User

Hi @Zuzana ,

 

In Direct Query mode, if you're trying to show the maximum category number for each child ID across all related parent ID rows, your current DAX measure isn't correctly removing the row-level filter context. To achieve the desired result—where each row displays the same maximum category number per child ID—you should revise the measure to explicitly remove filters on everything except the child ID. You can use the ALLEXCEPT function to achieve this. Here's the corrected measure:

#Max Cat =
CALCULATE(
    MAX('your_table'[category number]),
    ALLEXCEPT('your_table', 'your_table'[child ID])
)

This version ensures that the measure returns the same maximum value of category number for all rows sharing the same child ID, regardless of other filters in the table. Just replace 'your_table' with the actual name of your table. This approach works in Direct Query mode and avoids the pitfalls of SELECTEDVALUE not resolving correctly due to row context limitations.

 

Best regards,

Hi @DataNinja777 ,

Thank you very much for your solution. This seems to be working well. 🙂 

 

You saved me! 
Have a wonderful weekend. 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.