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
shanwise101
New Member

encontrar el último registro por día, por cliente

Hola a todos,

Tengo un conjunto de datos que captura varios clientes que actualizan un campo de cantidad varias veces al día, diferenciado por una marca de tiempo.

Necesito ser capaz de mostrar a través de tabla o columna o medida:

  • el último registro por día
  • por cliente
  • y la cantidad asociada.

Dataset:

ClienteTimestampQty
Cliente A4/04/2020 11:070
Cliente A4/04/2020 16:241
Cliente A4/04/2020 20:031
Cliente A5/04/2020 8:172
Cliente A5/04/2020 10:532
Cliente A5/04/2020 12:292
Cliente A5/04/2020 13:182
Cliente A5/04/2020 16:532
Cliente A5/04/2020 19:593
Cliente A6/04/2020 8:513
Cliente A6/04/2020 9:561

Resultado (con cliente adicional para el contexto)

ClienteTimestampQty
Cliente A4/04/2020 20:031
Cliente A5/04/2020 19:593
Cliente A6/04/2020 9:561
Cliente B6/04/2020 20:022
Cliente B7/04/2020 7:552

Cualquier guía sería muy apreciada, muchas gracias a todos.

3 REPLIES 3
v-eachen-msft
Community Support
Community Support

Hola @shanwise101 ,

También puede usar Power Query para hacerlo.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ldA7CoAwDAbgq5TOhSbpS7OJxygdHUXwcX8rQtFF24zJlxD+GOV4bPsyT6sYRCmppNVgNQGBQGQIrxnIpGoWPZPNHazjBAzmj7vCO8aQG1SnEdiZBk5MfQM3jF0D923P9OyuZ8wX949gHNbrfNvfoacT", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, timestamp = _t, Qty = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Customer", type text}, {"timestamp", type datetime}, {"Qty", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Date.From([timestamp])),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Customer", "Custom"}, {{"Max", each _, type table [Customer=text, timestamp=datetime, Qty=number, Custom=date]}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"Max"}),
    #"Added Custom1" = Table.AddColumn(#"Removed Other Columns", "MaxDate", each List.Max([Max][timestamp])),
    #"Expanded Count" = Table.ExpandTableColumn(#"Added Custom1", "Max", {"Customer", "Qty", "timestamp"}, {"Max.Customer", "Max.Qty", "Max.timestamp"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Count", each ([Max.timestamp] = [MaxDate])),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"MaxDate"})
in
    #"Removed Columns"

Aquí está el resultado.

1-1.PNG

Aquí está el archivo de prueba para su referencia.

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
camargos88
Community Champion
Community Champion

Hola @shanwise101 ,

Compruebe este código para una columna calculada:

Max_Timestamp = 
VAR _date = 'Table'[timestamp]
VAR _customer = 'Table'[Customer]
VAR _Qty = 'Table'[Qty]
RETURN
IF (_date = 
CALCULATE(
            MAX('Table'[timestamp]), 
            FILTER('Table', 
                    'Table'[Customer] = _customer && 
                    'Table'[Qty] = _Qty &&
                    DATE(YEAR('Table'[timestamp]), MONTH('Table'[timestamp]), DAY('Table'[timestamp])) = DATE(YEAR(_date), MONTH(_date), DAY(_date))
            )
), 1, 0)


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



mahoneypat
Employee
Employee

Aquí hay una manera de obtener el resultado deseado como una tabla calculada DAX

1. Agregue una columna Fecha a su tabla (llamé a su tabla de datos de ejemplo "Cantidad") con esto -

Fecha: FORMAT(Cantidad[marca de tiempo], "MM/DD/AAAA")
2. Haga una tabla DAX con esta expresión

Latest =
ADDCOLUMNS (
    SUMMARIZE ( Qty, Qty[Customer], Qty[Date] ),
    "@time", CALCULATE ( MAX ( Qty[timestamp] ) ),
    "@Qty",
    VAR maxtime =
        CALCULATE ( MAX ( Qty[timestamp] ) )
    RETURN
        CALCULATE ( AVERAGE ( Qty[Qty] ), Qty[timestamp] = maxtime )
)

También puede utilizar lo anterior en una variable de medida y realizar un análisis adicional al respecto, si prefiere una medida.

Si esto funciona para usted, márquelo como la solución. Los elogios también son apreciados. Por favor, avísame si no.

saludos

palmadita





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.