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
taumirza
Helper IV
Helper IV

Alternative to MAX

is there any function which gives us max of values in terms of strings?

not integer 0's and true or false

it should return the column value.

2 ACCEPTED SOLUTIONS
OwenAuger
Super User
Super User

@taumirza

You can use LASTNONBLANK to return the 'maximum' of a text column.

See this article on SQLBI:

https://www.sqlbi.com/articles/alternative-use-of-firstnonblank-and-lastnonblank/

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

Hi @taumirza,

 

That's right, LASTNONBLANK/FIRSTNONBLANK order text lexicographically.

 

If you want the text value with greatest length, you can do this or something similar:

Longest Text Value =
CALCULATE (
    LASTNONBLANK ( MyTable[TextColumn], 0 ),
    TOPN ( 1, VALUES ( MyTable[TextColumn] ), LEN ( MyTable[TextColumn] ) )
)

If there are ties, they are broken by LASTNONBLANK.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

4 REPLIES 4
OwenAuger
Super User
Super User

@taumirza

You can use LASTNONBLANK to return the 'maximum' of a text column.

See this article on SQLBI:

https://www.sqlbi.com/articles/alternative-use-of-firstnonblank-and-lastnonblank/

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hi @OwenAuger,

Actually i found this blog after a little search.

Anyway thank you so much for your reply.

Hi @OwenAuger,

 

The LastNonBlank and FirstNonBlank fuctions giving me the first and last nonblank strings but i need values with maximum character length in the column.!!

Hi @taumirza,

 

That's right, LASTNONBLANK/FIRSTNONBLANK order text lexicographically.

 

If you want the text value with greatest length, you can do this or something similar:

Longest Text Value =
CALCULATE (
    LASTNONBLANK ( MyTable[TextColumn], 0 ),
    TOPN ( 1, VALUES ( MyTable[TextColumn] ), LEN ( MyTable[TextColumn] ) )
)

If there are ties, they are broken by LASTNONBLANK.


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

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.