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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Efren2000
Frequent Visitor

Obtener costo promedio

Hola a todos

Tengo el siguiente problema.

Quiero obtener el costo promedio de los siguientes movimientos, logre obtener el valor de la fecha de una fila anterior esto ya que el costo promedio debe de ser el mismo hasta que cambien el movimiento a una entrada de importacion y re hacer el calculo de "costo X Tipo de Cambio" X "Saldo final", de la siguiente manera recuró la fecha de la fila anterior

_Costo Unitario Calculado =
VAR fechamin = MAX(Movimientos[UltimoCambio])
VAR fecha_anterior = CALCULATE(MAX(Movimientos[UltimoCambio]),TOPN(1,FILTER(ALLSELECTED(Movimientos),Movimientos[UltimoCambio]< fechamin)))
RETURN fecha_anterior
Captura de pantalla 2024-08-26 130839.png
y asi es como deberia de quedar
Captura de pantalla 2024-08-26 171741.png
3 REPLIES 3
Anonymous
Not applicable

Hi, @Efren2000 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1724739995987.png
2.Insert the index column

vlinyulumsft_1-1724739995989.png
3. Below are the measure I've created for your needs:

MEASURE = 
IF (
    MAX ( 'Movimientos'[Mov] ) <> "2.1 Factura",
    CALCULATE (
        SUM ( 'Movimientos'[Costo x Tipo de Cambio] ),
        FILTER (
            ALLSELECTED ( 'Movimientos' ),
            'Movimientos'[Index]
                = MAX ( 'Movimientos'[Index] ) + 1
        )
    ),
    SUM ( 'Movimientos'[Costo x Tipo de Cambio] )
)

4.Here's my final result, which I hope meets your requirements.

vlinyulumsft_2-1724740050169.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

Hi @v-linyulu-msft

Thank you for your help

My index for me is the column "UltimoCambio" and I have this excel that can help you to understand better

Captura de pantalla 2024-08-27 092751.png

this is how it should look and you can look that when it switch mov for "entrada importacion" the calculated cost changes

 

Kind Regards

Anonymous
Not applicable

Hi, @Efren2000 

Thank you for your correction, but I think I did not express clearly the reason why I chose to insert index.

 

If I use the "UltimoCambio" column you provided as the index column, it is difficult to uniquely identify the number of rows because it has the same content, so I choose to insert an index column as the identifier. And my initial judgment statement also takes into account the "UltimoCambio" column.

 

Thank you for your understanding.

 
Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.