THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

SQLBI - Marco Russo

Please visit the same blog at - comments are now disabled here but you can comment on the new blog (all blog posts available here are available there, too).
You can follow me on Twitter: @marcorus


You are probably used to think to FIRSTNONBLANK and LASTNONBLANK as DAX functions related to time-intelligence calculations (usually for semi-additive measures). However, these functions have a syntax and a behavior that can be useful in other scenarios.

For example: you might be aware that MIN and MAX cannot be used with text columns. However, you can use FIRSTNONBLANK and LASTNONBLANK instead of MIN and MAX, respectively. In fact, this is the corresponding syntax:

MIN ( <column> ) = FIRSTNONBLANK ( <column>, 1 )
MAX ( <column> ) = LASTNONBLANK ( <column>, 1 )

In my new article Alternative use of FIRSTNONBLANK and LASTNONBLANK, you can find a broader explanation of FIRSTNONBLANK and LASTNONBLANK behavior, with other scenarios where these functions can be useful.

Published Tuesday, February 24, 2015 10:35 AM by Marco Russo (SQLBI)
Filed under: , ,



Vincent Lau ( said:

This article is probably not very intuitive, why would we need to find the maximum for a text column?

January 14, 2017 9:54 PM

Marco Russo (SQLBI) said:

Is not very common, but it happens in case you want to get the last transaction when it has a format such as ABC00129 instead of a number.

January 19, 2017 10:52 AM

Blaine McKillip said:

Very helpful, thanks!   Great for use against a data set not well organized where you have limited controls

August 20, 2017 11:08 AM
New Comments to this post are disabled

About Marco Russo (SQLBI)

Marco Russo is a consultant, writer and trainer specialized in Business Intelligence with Microsoft technologies. He runs the SQLBI.COM website, which is dedicated to distribute resources useful for BI developers, like Integration Services components, Analysis Services models, tools, technical information and so on. Marco is certified as MCT, MCDBA, MCSD.NET, MCSA, MCSE+I.

This Blog



Privacy Statement