Forum Discussion

AN2021's avatar
AN2021
Frequent Visitor
5 years ago
Solved

Substract column with a constant from another column

Hi, I want to calculate as follow:

Minus "Value" for each bucket with "Value" from bucket 1 group by "Division"

DivisionBucketValueDif

A

170 (7 - 7)
A281 (8 - 7)
A392 (9 - 7)
B1100 (10 - 10)
B2133 (12 - 10)
B3155 (15 - 10)

 

I try to use this DAX, but it return to sum up all "Value" from Bucket = 1 from all Division.

 

Total Value = SUM(MY_TABLE[Value])
 
Dif =
CALCULATE(
[Total Value],
FILTER(
ALL(MY_TABLE),
MY_TABLE[Bucket] = 1
)
)
 
DivisionBucketValueDif

A

17-7 (7 - 17)
A28-9 (8 - 17)
A39-8 (9 - 17)
B110-7 (10 - 17)
B213-3 (12 - 17)
B315-2 (15 - 17)
  • AN2021 

    Try this code please:

    Difference = 
    Table3[Value]
    -
    CALCULATE(
        sum(Table3[Value]),
        Table3[Bucket] = 1,
        ALLEXCEPT(Table3,Table3[Division])
    ) 

8 Replies

  • themistoklis's avatar
    themistoklis
    Icon for Community Champion rankCommunity Champion

    AN2021 

     

    Try the following measure:

     

     

    Measure3 =
    VAR __bucket1 =
        CALCULATE (
            SUM ( Sheet1[Value] ),
            FILTER ( ALLEXCEPT ( Sheet1, Sheet1[Division] ), Sheet1[Bucket] = 1 )
        )
    RETURN
        SUM ( Sheet1[Value] ) - __bucket1

     

     

    Workspace attached on this message

    • AN2021's avatar
      AN2021
      Frequent Visitor

      Hi themistoklis

      Its work, but wonder why if I have more column, its not works?

      From your example I add 1 column named Dim1

       

       

      • themistoklis's avatar
        themistoklis
        Icon for Community Champion rankCommunity Champion

        AN2021 

         

        It still works with new dimensions.

        See attached file.

         

        If you could share you file so as to have a look at it that would be great

         

         

  • AN2021 

    Add the following column:

    Dif = Table3[Value] - CALCULATE( MIN(Table3[Value]), ALLEXCEPT(Table3,Table3[Division]))

     



    • AN2021's avatar
      AN2021
      Frequent Visitor

      Hi Fowmy

       

      Actually I want to get the "Value" from Bucket = 1, not the Min of "Value". Your solution might work with my example, but in my actual case some "Value" in Bucket = 1 is not the smallest one.

      • Fowmy's avatar
        Fowmy
        Icon for Super User rankSuper User

        AN2021 

        Try this code please:

        Difference = 
        Table3[Value]
        -
        CALCULATE(
            sum(Table3[Value]),
            Table3[Bucket] = 1,
            ALLEXCEPT(Table3,Table3[Division])
        )