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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Powerbichile
New Member

Lookupvalue con filtro por ultima fecha

Hola Amigos,

por favor su ayuda,

Tengo una tabla con datos de costos por fechas con este formato:

 

Codigo ProductoFechaCosto
131-11-202110566
105-12-202225365
201-05-202035
220-06-202155
222-06-202122

 

Y otra tabla con este formato:

 

Codigo ProductoTipoU.M.GrupoNUEVA FILA COSTO
1xParu25365
2xParu22
3yUnidadv...

 

Estoy intentando agregar una columna "NUEVA FILA COSTO" a esta tabla con el valor con la fecha más reciente...

 

Ultimo Costo = LOOKUPVALUE('softland iw_costop'[CostoUnitario],'softland iw_costop'[CodProd],'softland IW_vsnpProductos'[CodProd],0)

 

Intenté con esto, pero no se como filtrar por el último valor...

 

Por favor su ayuda...

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Powerbichile 

You can create two blank query in Power BI, then put the following code in Advanced Editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZYzBCcAwDAN38bsgS669TMj+a7RxIRD6O98ZjWG0y+QiSIS/Bz2rbF47CRRycUZlF33FkVhPcViioLWUf92s1rHXvdeZpw7cjTbnAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Codigo Producto" = _t, Fecha = _t, Costo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Codigo Producto", Int64.Type}, {"Fecha", type date}, {"Costo", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Codigo Producto"}, {{"Count", each _, type table [Codigo Producto=nullable number, Fecha=nullable date, Costo=nullable number]}, {"MaxDate", each List.Max([Fecha]), type nullable date}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Fecha", "Costo"}, {"Fecha", "Costo"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Count", "Custom", each if [Fecha]=[MaxDate] then [Costo] else null)
in
    #"Added Custom"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaoA4oDEIiBZCsRGpsZmpkqxOtFKRphyRmAJYyCzEohD8zJTElOAjDIgVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Codigo Producto" = _t, Tipo = _t, #"U.M." = _t, Grupo = _t, #"NUEVA FILA COSTO" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Codigo Producto", Int64.Type}, {"Tipo", type text}, {"U.M.", type text}, {"Grupo", type text}, {"NUEVA FILA COSTO", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"NUEVA FILA COSTO"}),
    #"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Codigo Producto"}, Query1, {"Codigo Producto"}, "Query1", JoinKind.LeftOuter),
    #"Expanded Query1" = Table.ExpandTableColumn(#"Merged Queries", "Query1", {"Custom"}, {"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Query1", each ([Custom] <> null))
in
    #"Filtered Rows"

Output

vxinruzhumsft_0-1692585427101.png

 

Best Regards!

Yolo Zhu

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

1 REPLY 1
Anonymous
Not applicable

Hi @Powerbichile 

You can create two blank query in Power BI, then put the following code in Advanced Editor in power query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZYzBCcAwDAN38bsgS669TMj+a7RxIRD6O98ZjWG0y+QiSIS/Bz2rbF47CRRycUZlF33FkVhPcViioLWUf92s1rHXvdeZpw7cjTbnAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Codigo Producto" = _t, Fecha = _t, Costo = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Codigo Producto", Int64.Type}, {"Fecha", type date}, {"Costo", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Codigo Producto"}, {{"Count", each _, type table [Codigo Producto=nullable number, Fecha=nullable date, Costo=nullable number]}, {"MaxDate", each List.Max([Fecha]), type nullable date}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Fecha", "Costo"}, {"Fecha", "Costo"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Count", "Custom", each if [Fecha]=[MaxDate] then [Costo] else null)
in
    #"Added Custom"
let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUaoA4oDEIiBZCsRGpsZmpkqxOtFKRphyRmAJYyCzEohD8zJTElOAjDIgVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Codigo Producto" = _t, Tipo = _t, #"U.M." = _t, Grupo = _t, #"NUEVA FILA COSTO" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Codigo Producto", Int64.Type}, {"Tipo", type text}, {"U.M.", type text}, {"Grupo", type text}, {"NUEVA FILA COSTO", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"NUEVA FILA COSTO"}),
    #"Merged Queries" = Table.NestedJoin(#"Removed Columns", {"Codigo Producto"}, Query1, {"Codigo Producto"}, "Query1", JoinKind.LeftOuter),
    #"Expanded Query1" = Table.ExpandTableColumn(#"Merged Queries", "Query1", {"Custom"}, {"Custom"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Query1", each ([Custom] <> null))
in
    #"Filtered Rows"

Output

vxinruzhumsft_0-1692585427101.png

 

Best Regards!

Yolo Zhu

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

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors