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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Max value of column based on certain text in another column

Hello,

 

I have a column 'X' with numerical values in it and another column 'Y' with text in it. In column 'Y' it will either contain the text 'A', 'B' or 'C'. I want to return the maximum value from column 'X' but with a filter so it only considers values where there is an 'A' in the row from the 'Y' column.

 

In power query I added a custom column with the formula:

IF text.contains([Y], "A") then [X] else 0

But when I then create a new measure with the DAX function 'MAX' for my new custom column it doesn't return the maximum value. It returns 98 when the actual max value is 1200. Is there a reason why it isn't searchin the whole column? When I look through my custom column in power query i can see a lot of numbers bigger than 98, but all of these seem to be ignored.

 

Can anyone help with this?

1 ACCEPTED SOLUTION
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this measure

 

Max Value = 

CALCULATE(
    MAX('Table'[X]),'Table[Y] = "A")
)

 

Regards,

Harsh Nathani

 

View solution in original post

3 REPLIES 3
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Try this measure

 

Max Value = 

CALCULATE(
    MAX('Table'[X]),'Table[Y] = "A")
)

 

Regards,

Harsh Nathani

 

Anonymous
Not applicable

Hi @harshnathani,

 

This has worked, thanks for your help. It seems so simple now!

Fowmy
Super User
Super User

@Anonymous 

I am not sure about your Power Query code 
It easy to add the Column that gives you the MAX by category in the model than in Power Query.
Add the following column: DAX

Max Value = 

CALCULATE(
    MAX('Table'[x]),
    ALLEXCEPT('Table','Table'[y])
)



________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors