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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
Zuzana
New Member

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Kudoed Authors