Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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:

:

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:

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

 

  • 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

3 Replies

  • mahoneypat's avatar
    mahoneypat
    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

  • Anonymous's avatar
    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

  • Jimmy801's avatar
    Jimmy801
    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"

    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