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
Anonymous
Not applicable

Power Query: Use El valor de filas anteriores en el cálculo actual

Gracias de antemano por la ayuda! Tengo una tabla que estoy tratando de rellenar los valores NULL usando el valor de registros anteriores. A continuación se muestra un ejemplo. El campo Valor tiene algunos valores que faltan para las categorías multipe. La fórmula para rellenar los valores que faltan es simplemente multiplicar el número de valor de la fila anterior (dentro de la categoría) por el valor de Factor de crecimiento. En este ejemplo, la función rellenaría (55 x 0.8) 44 para el primer valor que falta en la categoría A y 75,2 (94 x 0,8) para el primer valor que falta en la categoría B. La función se repetiría hasta que se rellenen todos los valores que faltan.

CategoríaFactor de crecimientoValor
A0.5100
A1.1110
A0.888
A0.979
A0.755
A0.8
A0.9
A0.4
A0.6
A0.7
B0.5200
B0.8160
B1.2192
B0.7134
B0.794
B0.8
B0.9
B0.4
B0.6
B0.7
3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hola @KyleSchmile

lbendlinLa respuesta de 's le ha mostrado el camino por Power Query.

podría probar mi manera de lograr su objetivo en Dax.

En primer lugar, agregamos una columna de índice en Power Query Editor.

1.png

Entonces dejemos ques agregar otra columna de índice por columna calculada.

Category ID =

var _rank=RANKX(FILTER('Table','Table'[Category]=EARLIER('Table'[Category])),'Table'[Index],,ASC)

var _avgcountofP=DIVIDE(COUNTROWS('Table'),CALCULATE(DISTINCTCOUNT('Table'[Category]),ALL('Table')))

var _c=if(_rank>_avgcountofP,_avgcountofP,_rank)

return _c

Ahora deja ques utilizar una columna de medida para rellenar el valor.

Medidas ?

IF (

    ISBLANK ( MAX ( 'Table'[Value] ) ),

    PRODUCTX (

        FILTER (

            ALL ( 'Table' ),

            'Table'[Category] = MAX ( 'Table'[Category] )

                && 'Table'[Category ID] <= MAX ( 'Table'[Category ID] )

        ),

        'Table'[Growth Factor]

    )

        * CALCULATE (

            VALUES ( 'Table'[Value] ),

            FILTER (

                ALL ( 'Table' ),

                'Table'[Category] = MAX ( 'Table'[Category] )

                    && 'Table'[Category ID] = 1

            )

        ) / 0.5,

    MAX ( 'Table'[Value] )

)

Resultado:

2.png

Puede descargar el archivo pbix de este enlace:

https://qiuyunus-my.sharepoint.com/:u:/g/personal/tongzhou_qiuyunus_onmicrosoft_com/EQUN7KKiMIFLp_qo...

Saludos

Rico Zhou

Si este post ayuda,entonces considere Aceptarlo como la solución para ayudar a los otros miembros a encontrarlo más rápidamente.

lbendlin
Super User
Super User

¿Tiene que ser Power Query? En DAX puede salirse con la suya con una función ProductX.

Todavía estoy aprendiendo Power Query, pero así es como empezaría a abordarlo:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY5LCsAgDESvUrIuYmz8ZFmvId7/GlUqGmYz8B75TGv00k3exZHsPfX7N+x4Jh/jXRlZihE6MqsReWSMsHLBhmUBTsB5c901w6pZ9wdOx7ALMzWYmXmFHwGjAmfsIwUW4AS8ivYP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, #"Growth Factor" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Growth Factor", type number}, {"Value", type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added Custom1" = Table.AddColumn(#"Added Index", "Custom", each if [Index] = 0 
or [Category] <> #"Added Index"[Category]{[Index]-1} then [Value]
else [Growth Factor]),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Value adj", each if [Index] = 0 
or [Category] <> #"Added Index"[Category]{[Index]-1} then [Value]
else #"Added Custom1"[Custom]{[Index]-1}*[Growth Factor])
in
    #"Added Custom"

Esta no es una solución completa todavía, todavía necesita el equivalente "productx" y la agrupación para que funcione.

Aquí hay una "solución" bastante burda, pero hace lo que necesita. Como entiendo en el equivalente de PRODUCTX() en Power Query es List.Product()

Código de consulta de energía:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XY5LCsAgDESvUrIuYmz8ZFmvId7/GlUqGmYz8B75TGv00k3exZHsPfX7N+x4Jh/jXRlZihE6MqsReWSMsHLBhmUBTsB5c901w6pZ9wdOx7ALMzWYmXmFHwGjAmfsIwUW4AS8ivYP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, #"Growth Factor" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Growth Factor", type number}, {"Value", type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"Added IndexOffset" = Table.AddColumn(#"Added Index", "IndexOffset", each if [Index] = 0 
or [Category] <> #"Added Index"[Category]{[Index]-1} then [Index]
else null),
    #"Filled Down" = Table.FillDown(#"Added IndexOffset",{"IndexOffset"}),
    #"Added Custom" = Table.AddColumn(#"Filled Down", "Custom", each if [Index] = 0 
or [Category] <> #"Filled Down"[Category]{[Index]-1} then [Value]
else [Growth Factor]),
    #"Added Result" = Table.AddColumn(#"Added Custom", "Result", each List.Product(List.Range(#"Added Custom"[Custom],[IndexOffset],[Index]+1-[IndexOffset])))
in
    #"Added Result"

Resultado:

lbendlin_0-1595469685081.png

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.