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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Efren2000
Frequent Visitor

I need a dax calculate average cost

Hi all

I need a dax that calculate average cost, I have the following columns where my column index is "UltimaCambio" and This is what it looks like:

Captura de pantalla 2024-08-26 130839.png

 

I calculated last row with following formula beacuse the average cost is calculated:

Average Cost = Total Cost / Number of Units Produced

 

and my total cost is calculated multiplicate my last accumulated cost * accumulated cant

 

and I use the following dax for calculate the last row:

_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

 

I have this excel with the columns calculated and this is example how it has to be seen:

Captura de pantalla 2024-08-27 092751.png

2 REPLIES 2
Anonymous
Not applicable

Hi @Efren2000 

 

If I understand you correctly, you want to calculate the average cost. Do you need to calculate the average of the column Costo x Tipo de Cambio? So in your example data, the average is 46.65, is that correct? 

 

Since you gave two screenshots, but some of the column names seem to be different in both screenshots, I'm a bit confused and need to check with you. Is the second screenshot your expected result?

 

Do Cantidad Mov., COSTO CALCULADO and Acumulado Cantidad in Figure 2 correspond to Movimientos, Costo x Tipo de Cambio and Saldo Final in Figure 1 respectively?

 

It would be great if you could explain your needs in more detail. Thanks.

 

Best Regards,
Yulia Xu

Thak you for respond

 

I need a dax where it is calculated Average Cost = Total Cost (Total Valor Inv) / Number of Units Produced (Accumulated Amount)

Row A4: In PBI, we already calculte this values from previous month

Row A5: Actual Value =E5*L4

              Accumulated Amount: We already have the measure

             Acumulated Value: =H4*L4

             Total Valor Inv =G5+I5

             Cost calculate= J5/H5

 

Row A6: Actual Value =E6*L5

              Accumulated Amount: We already have the measure

             Acumulated Value: =H5*L5

             Total Valor Inv =G6+I6

             Cost calculate= J6/H6

 

Row A10: Actual Value =E10*F10

              Accumulated Amount: We already have the measure

             Acumulated Value: =H9*L9
             Total Valor Inv =G10+I10
             Cost calculate= J10/H10

Row A11 Same as Row A6…

Efren2000_0-1724948705525.png

This is what I have in PBI 

Efren2000_1-1724948741219.png

In this dax I recover the last value:
_Fecha Anterior =
VAR fechamin = MAX(Movimientos[UltimoCambio])
VAR fecha_anterior = CALCULATE(MAX(Movimientos[UltimoCambio]),FILTER(ALLSELECTED(Movimientos),Movimientos[UltimoCambio]<fechamin))
RETURN fecha_anterior

 

Acumulado Cantidad =
[_Ending Balance date] + [Saldo Almacen Mes Anterior Detalle]
 
Saldo Almacen Mes Anterior Detalle =
VAR _index = SELECTEDVALUE(Movimientos[UltimoCambio])
VAR _artical = SELECTEDVALUE(Movimientos[Articulo])
VAR _mov = SELECTEDVALUE(Movimientos[Mov])
var totalant= CALCULATE([SaldoAlmacen], FILTER(ALL(Movimientos),Movimientos[Articulo] = _artical && Movimientos[Mov]<>"2.4 Bonificacion Venta") ,FILTER(ALL(Calendario), Calendario[Date]<MIN(Calendario[Date])))
RETURN totalant
 
_Ending Balance date=
VAR _index = SELECTEDVALUE(Movimientos[UltimoCambio])
VAR _artical = SELECTEDVALUE(Movimientos[Articulo])
--var totalant= CALCULATE([SaldoAlmacen], FILTER(ALL(Movimientos),Movimientos[Articulo] = _artical) ,FILTER(ALL(Calendario), Calendario[Date]<MIN(Calendario[Date])))
VAR total= CALCULATE([SaldoAlmacen],FILTER(ALLSELECTED(Movimientos),Movimientos[UltimoCambio] <= _index && Movimientos[Articulo] = _artical))
RETURN total

 

Best Reguards

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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