Forum Discussion

mibu's avatar
mibu
Microsoft Employee
6 years ago

Numerous Subtotals Formula

Hey Everybody!

 

I have the following data:

Type / Units

A / 100

B / 200

C / 300

 

Is there a formula that will allow me to show the following in a Matrix:

Type/Units

A / 100

B / 200

C / 300

A+B / 300

A+B+C / 600

 

Thanks in advance!

mibu

22 Replies

  • Hi mibu ,

     

    Create a new table with the following format

    CAT       ID

    A 1
    B 2
    C 3
    A+B 4
    A+B+C 5

     

    Now add the following measure to your model.

    CALCULATION =
    SWITCH (
        TRUE ();
        MAX ( CAT[ID] ) < 4; CALCULATE ( SUM ( 'Table'[Units] ); 'Table'[Type] = VALUES ( CAT[CAT] ) );
        MAX ( CAT[ID] ) = 4; CALCULATE (
            SUM ( 'Table'[Units] );
            FILTER ( ALL ( 'Table'[Type] ); 'Table'[Type] IN { "a"; "B" } )
        );
        CALCULATE ( SUM ( 'Table'[Units] ); ALL ( 'Table'[Type] ) )
    )

     

     Then use the previous table information and the measure to create your matrix.

     

    Regards,

    MFelix

    • mibu's avatar
      mibu
      Microsoft Employee

      MFelix  Thanks for your post!  I am currently reviewing your proposed solution.  very best, mibu

    • mibu's avatar
      mibu
      Microsoft Employee

      Hi MFelix 

      Is it possible to approach the problem in this way:

      Create a new table as follows (table and .pbix file ABCTEST uploaded to dropbox here

      And then come up with a Calculation/Measure/Formula that allows us to show the following in a single MATRIX:

      A through H… each in its own Row (alphabetically)…

      A+B… in its own Row (below row B)…

      C+D+E … in its own Row (below row E)…

      A+B+C+D+E...  in its own Row (below C+D+E Subtotal row)...

      A+B+C+D+E+F...  in its own Row (below row F)...

      G+H… in its own Row (below row H)…

      Thanks!

      Mibu

      Nathaniel_C 

      v-xicai 

  • Nathaniel_C's avatar
    Nathaniel_C
    Community Champion

    mibu ,



     


    Let me know if you have any questions.

    If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
    Nathaniel

    Sum A+ B, or sum A+B+C = 
    var _A = Calculate(SUM(myTable[Units]),ALLEXCEPT(myTable,myTable[Type ]),myTable[Type ]= "A")
    var _B = Calculate(SUM(myTable[Units]),ALLEXCEPT(myTable,myTable[Type ]),myTable[Type ]= "B")
    var _C = Calculate(SUM(myTable[Units]),ALLEXCEPT(myTable,myTable[Type ]),myTable[Type ]= "C")
    
    
    //var _AB = (myTable[Type ] = "A"|| myTable[Type ] = "B", myTable[Units]))
    return
    IF(MAX(myTable[Type ])="B",_A+_B, If(MAX(myTable[Type ]) = "C", _A+_B+ _C))

     

    • mibu's avatar
      mibu
      Microsoft Employee

      Nathaniel_C Thanks for your post!  I am currently reviewing your proposed solution.  very best, mibu

    • mibu's avatar
      mibu
      Microsoft Employee

      Hi Nathaniel_C 

      Expanding the scope a bit...  to be more in line with the problem I am trying to solve.

      Here is a faux sample set that resembles the eight variables I am working with...  you can see your A+B and A+B+C solutions in Column AB/ABC:

      Here is the output and matrix format I am trying to achieve:

      Thanks in advance for your feedback about trying to solve this problem.  I am aware that Subtotals/Row subtotals toggled On will sum Grand Total.

      Thanks!

      mibu

      • Nathaniel_C's avatar
        Nathaniel_C
        Community Champion

        Hi mibu ,
        What are you trying to do? This looks like something that you won't be able to solve in Power BI alone. Might you provide us with a pbix. I think you will need to create other tables as well.
        Thank you,

        Nathaniel

  • v-xicai's avatar
    v-xicai
    Community Support

    Hi mibu ,

     

    You can create measure to get cumulative total like DAX below, then put it into Values box of Matrix visual.

     

    Cumulative total = CALCULATE(SUM(Table1[Units]),FILTER(ALLSELECTED(Table1), Table1[Type] <=MAX(Table1[Type])))

     

    Best Regards,

    Amy

     

    Community Support Team _ Amy

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

    • mibu's avatar
      mibu
      Microsoft Employee

      v-xicai Thanks for your post!  I am currently reviewing your proposed solution.  very best, mibu

    • mibu's avatar
      mibu
      Microsoft Employee

      Hi v-xicai 

      I did per your guidance and get the following result:

      What I need however is for the Matrix to read:

      Cumulative total / 3600

      I need it to show as a row, not a column in the Matrix.

      Thoughts?

      Thanks!

      mibu

      • mibu's avatar
        mibu
        Microsoft Employee

        Hi v-xicai 

        I am looking for a Measure that will allow me to create the following:

        Sum of A+B

        Sum of A+C...

        THEN...  be able to pull them both into Row section of a single Matrix.

        Matrix will automally Grand Total A+B+C.

        Including other contributors to this thread:

        Nathaniel_C 

        MFelix 

        Thanks Team!