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
webportal
Impactful Individual
Impactful Individual

Get the last non blank value of a column with DAX

webportal_0-1614548109052.png

I want a Column to find the last non blank value from "Class" following the order of the "Date" column.

Thus, the first 3 rows will be empty.

Rows from 31/01/2016 to 30/04/2016 will be A.

 

And ALL the remaing rows will be B.

 

I know the following will work:

Coluna =
VAR EstaData = Tabela[Data]
VAR DataMax = CALCULATE(MAX(Tabela[Data]), FILTER(ALL(Tabela), Tabela[Data]<= EstaData && LEN(Tabela[Class])>0))
RETURN
CALCULATE(MAX(Tabela[Class]), FILTER(ALL(Tabela), Tabela[Data] = DataMax))
 
But... isn't there a better/cleaner way??

 

Thanks for helping!

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @webportal ,

You can create a calculated column as below:

Coluna =
CALCULATE (
    LASTNONBLANK ( 'Tabela'[Class], MAX ( 'Tabela'[Data] ) ),
    ALL ( 'Tabela' )
)

Get the last non blank value of a column with DAX.JPG

Best Regards

 

 

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
PierreArchen
Regular Visitor

Can you tell me more why this formula work ? Why use min function ? 

v-yiruan-msft
Community Support
Community Support

Hi @webportal ,

You can create a calculated column as below:

Coluna =
CALCULATE (
    LASTNONBLANK ( 'Tabela'[Class], MAX ( 'Tabela'[Data] ) ),
    ALL ( 'Tabela' )
)

Get the last non blank value of a column with DAX.JPG

Best Regards

 

 

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yiruan-msftThank you!

mahoneypat
Employee
Employee

Please try this measure expression, replacing T1 with your actual table name.

LNBV = LASTNONBLANKVALUE(T1[Date], MIN(T1[Class]))
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


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