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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

LASTNONBLANK

Hi there !!

 

I am wanting to add a column to my table and in this column I want to obtain the value that it gives me in the last date filtered with id.

 

I have an id column, a value column, a date column, and I want the new column to give me the value that is the most recent date. something like that:

:Capture.PNG

I want to get the last column. of the id B34001 its last date was 07/12/2020 and for that date the value ea 0.96 so in my new column I want that in all the id B34001 I get 0.96.

 

I have this:

Capture1.PNG

but now in the table they are slipping me some blank value. then I have as the last date the blank value and when I do the query I get the last blank value. How can I make it so that I don't get the last blank values? You should use LASTNONBLANK somewhere in the query but I don't know where.

 

Thanks in advance

 

regards

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

You can try this column expression, replacing Table with your actual table name.

 

Ultimo Valor = CALCULATE(LASTNONBLANKVALUE(Table[fecha], MAX(Table[valor])), ALLEXCEPT(Table, Table[id))

 

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


View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

if you are looking for a solution in Power Query then you can use Table.Group and group by id and apply to function. One to get the whole grouped table and the other is to calculate the value in the last date of "fecha". Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjJU0lEyMNQDIiMDEFPH0kwpVgdVwhCrhDG6DiMMoywwJECaDVFFoeYYGugYQSSMUc0xxhAFGWKKKgo3RCk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, fecha = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"id", type text}, {"fecha", type date}, {"Value", type number}}, "de-DE"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"id"}, {{"AllRows", each _, type table [id=text, fecha=date, Column1=number]}, {"MaxValue", each Table.Max(_,"fecha")[Value], type number}}),
    #"Expanded AllRows" = Table.ExpandTableColumn(#"Grouped Rows", "AllRows", {"fecha"}, {"fecha"})
in
    #"Expanded AllRows"

Jimmy801_0-1612938940070.png

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

 

Anonymous
Not applicable

if you are satisfied with a solution in power query and upload an example table that is copyable, II can try to search for what you ask

mahoneypat
Microsoft Employee
Microsoft Employee

You can try this column expression, replacing Table with your actual table name.

 

Ultimo Valor = CALCULATE(LASTNONBLANKVALUE(Table[fecha], MAX(Table[valor])), ALLEXCEPT(Table, Table[id))

 

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors