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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
nesrinehal20
Frequent Visitor

Calculation DAX

I have a Purchase file (article_code, designation, family, pmp) and file OF (num_of, article_code, designation, family, actual cost) and  file PF (article_code, quantity,num_of) I want to calculate consumption value = actual cost * pmp and then calculate                                material cost = consumption/quantity value. how to do this calculation in dax powerbi

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @nesrinehal20 

 

Please try the following possible solutions:

1. First, create the following measures to calculate total actual cost and pmp.

TotalActualCost = 
CALCULATE(
    SUM('OF'[actual cost]),
    ALLEXCEPT('OF', 'OF'[num_of])
)
TotalPMP = 
CALCULATE(
    SUMX(
        'OF',
        RELATED('PURCHASE'[pmp])
    ),
    ALLEXCEPT('OF', 'OF'[num_of])
)

2. Create the following measures to calculate consumption and material cost.

consumption = [TotalActualCost] * [TotalPMP]
material cost = 
DIVIDE(
    [consumption],
    CALCULATE(
        SUM('PF'[quantity]),
        ALLEXCEPT('PF', 'PF'[num_of])
    )
)

 

 

Best Regards,
Jarvis Tang
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

11 REPLIES 11
Anonymous
Not applicable

Hi @nesrinehal20 

 

The DAX used in the following tests may not fully meet your requirements as the example data you provided is too small for us to accurately perform aggregation calculations on the data. If this does not solve your problem, please provide slightly more example data and explain in detail what you are trying to achieve.


This is the relationship I've established, so please correct me if I've misinterpreted it.

vxianjtanmsft_1-1730948731393.png

Create the measures with the following DAX:

 

consumption = 
SUMX(
    'PURCHASE', 
    'PURCHASE'[pmp] * RELATED('OF'[actual cost])
)
material cost = DIVIDE([consumption], SUM(PF[quantity]), 0)

 

vxianjtanmsft_0-1730948696198.png

 

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

 

 

ok done but if the same item has several real cost and pmp values ​​and I must add them before multiplying them how to do it

Anonymous
Not applicable

Hi @nesrinehal20 

 

Please try the following possible solutions:

1. First, create the following measures to calculate total actual cost and pmp.

TotalActualCost = 
CALCULATE(
    SUM('OF'[actual cost]),
    ALLEXCEPT('OF', 'OF'[num_of])
)
TotalPMP = 
CALCULATE(
    SUMX(
        'OF',
        RELATED('PURCHASE'[pmp])
    ),
    ALLEXCEPT('OF', 'OF'[num_of])
)

2. Create the following measures to calculate consumption and material cost.

consumption = [TotalActualCost] * [TotalPMP]
material cost = 
DIVIDE(
    [consumption],
    CALCULATE(
        SUM('PF'[quantity]),
        ALLEXCEPT('PF', 'PF'[num_of])
    )
)

 

 

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

PhilipTreacy
Super User
Super User

@nesrinehal20 

 

You said that OF and PF are related by num_of but the images you shared of the data don't show that column.

 

Also we can't really work with images, providing data as tables or ideally providing the PBIX file you are using makes our jobs as volunteers much easier.  Typing out all the data in your (incomplete) images takes some time and will be prone to errors, making the answers we give you no use.

 

Please check this which might explain things better than I have

 

Re: How to Get Your Question Answered Quickly - Page 7 - Microsoft Fabric Community 

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


 PURCHASE FILE

code_articledesignationfamilymonthpmp
MPO0239acide citriqueMP13,71
EMO2636PrésentoirEM23.5

OF FILE

num_ofcode_articledesignationfamilleactual cost
OF2401-men001EM02636presentoirEM1150
OF2501-pro002MPO0239acideMP

120.5

PF FILE

sitenum_ofcode_pfdesignation_pfquantity
menOF2401-men001PFSN036Juto1500
PROof2501-pro002PRO012choco200
PhilipTreacy
Super User
Super User

@nesrinehal20 

 

Are these CSV files, Excel, PBIX?

 

You shoudl have all the data (files) in a single PBIX fiel where you can create relationships between the data tables.  DAX Measures can then be written to do what you want.

 

Without the files/data it's hard to give you much more than this so can you please supply samples of these files?

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


i have excel imported in powerbi, realtionship are created. i want to know the dax calculation measure

@nesrinehal20 

 

Please show us your data.  Hard to write DAX when you have to guess what the data is!



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


hi @nesrinehal20 ,

 

how are OF and PF related?

FreemanZ
Super User
Super User

hi @nesrinehal20 

 

try like:

consumption value =

SUMX(Purchase, Purchase[pmp]*RELATED(OF([actual cost]))

 

for material cost, how are OF and PF related?

OF and PF are related by num_of

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors