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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
Employee
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
Employee
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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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
Top Kudoed Authors