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
Singh_Yoshi
Helper I
Helper I

DAX Code not working

I have following table in BI. 

ItemCost
18" Alloy-23000
20" Alloy31000
Air Bag5000
Deatc250

 

I want to subtract 18" Alloy cost(-23000) from 20" Alloy(31000) and remove 18" Alloy from the table. I Used following Dax function and it returns above table as out without doing any subtraction. Please correct my code or help me with new code. Thank you in advance.
Used DAX:

 

IF (
[Item] = "20"" Alloy",
[Costs] +
CALCULATE (
SUM([Costs]),
[Item] = "18" Alloy"
),
FJ11_16[Calculated Costs]
)

Desired Output:

 

ItemsCost
20" Alloy8000
Air Bag5000
Deatc250
1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Singh_Yoshi 

 

Please try this:

Measure1 = 
VAR _alloy =
    CALCULATE (
        SUM ( SampleData[Cost] ),
        FILTER (
            ALL ( SampleData[Item], SampleData[Cost] ),
            SampleData[Item] IN { "18"" Alloy", "20"" Alloy" }
        )
    )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( SampleData[Item] ) = "18"" Alloy", BLANK (),
        SELECTEDVALUE ( SampleData[Item] ) = "20"" Alloy", _alloy,
        SUM ( SampleData[Cost] )
    )

danextian_0-1735369483891.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
Singh_Yoshi
Helper I
Helper I

@danextian Thanks a lot. It is working. Please keep solving my queries.

danextian
Super User
Super User

Hi @Singh_Yoshi 

 

Please try this:

Measure1 = 
VAR _alloy =
    CALCULATE (
        SUM ( SampleData[Cost] ),
        FILTER (
            ALL ( SampleData[Item], SampleData[Cost] ),
            SampleData[Item] IN { "18"" Alloy", "20"" Alloy" }
        )
    )
RETURN
    SWITCH (
        TRUE (),
        SELECTEDVALUE ( SampleData[Item] ) = "18"" Alloy", BLANK (),
        SELECTEDVALUE ( SampleData[Item] ) = "20"" Alloy", _alloy,
        SUM ( SampleData[Cost] )
    )

danextian_0-1735369483891.png

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

I have a following table called Table1,

Model CodeMSRPLC
FJ111392000 
FJ161580000188000
FJ71762000182000
FJ81912000150000
FJ15193700025000
FJ122279000342000

 

I have few measures as below names and consists of Items and Cost

  • FJ11-16 - Sum of the measure is (-1674)
  • FJ16-7 - Sum of the measure is (70650)
  • FJ7-8 - Sum of the measure is (176150)
  • FJ8-15 - Sum of the measure is (-68150)
  • FJ15-12 - Sum of the measure is (28500)

1. Now I want to subtract LC cost - SUM of each measure

2. I need the percentage of (LC Cost - Sum of each measure)

 

Kindly help me with DAX code

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors