The LASTNONBLANK DAX function is used to returns the last value in the column for which the expression has a non blank value.
This function comes under Time Intelligence DAX functions category.
column- A column expression.
expression- An expression evaluated for blanks for each value of column.
Let’s get started
Import below dataset into Power BI desktop-
Table – Sales
Following these steps in order to implement Lastnonblank-
Step-1: Add one measure for Total Sales.
Total Sales = SUM(Sales[Sales])
Step-2: Add another measure and write below DAX for Lastnonblank.
LNB Date wise = LASTNONBLANK(Sales[Date], [Total Sales])
Step-3: Now add one card visual into Power BI report page and drag measure over it to see the result.
As you can see in above screenshot last non blank date according to Sales is 06/02/18.
Step-4: Now get last non blank for Month column, create one measure with below DAX.
LNB Month Wise = LASTNONBLANK(Sales[Month], [Total Sales])
As you can see in above screenshot Table data last non blank month is Feb but DAX measure returns Jan.
Understand the reason behind this-
Power BI DAX engine sort the column data in backend then returns the value. To check this – sort the table data month column wise in ascending order.
After sort you will see last non blank month is Jan, because DAX engine sort the month column data alphabetically and “J” comes in last.
Similar DAX functions: FIRSTNONBLANK
Hope you enjoyed the post. Your valuable feedback, question, or comments about this post are always welcome or you can leave us message on our contact form , we will revert to you asap.