Forum Discussion

Naveen29's avatar
Naveen29
Helper II
4 years ago
Solved

DAX help

Need help on the below scenerio: How to write a DAX?

actual table:

 

CategoryValue
A10
B20
C30

 

Out put expecting in the dashboard:

 

CategoryValue%
AA/C33%
BB/C67%
TotalMeasure = (A+B)/C100%
  • Naveen29  try this measure

    Measure =
    VAR _sum =
        DIVIDE (
            CALCULATE ( SUM ( t3[Value] ), FILTER ( t3, t3[Category] <> "C" ) ),
            CALCULATE ( SUM ( t3[Value] ), FILTER ( ALL ( t3 ), t3[Category] = "C" ) )
        )
    RETURN
        _sum
    

4 Replies

  • smpa01's avatar
    smpa01
    Community Champion

    Naveen29  try this measure

    Measure =
    VAR _sum =
        DIVIDE (
            CALCULATE ( SUM ( t3[Value] ), FILTER ( t3, t3[Category] <> "C" ) ),
            CALCULATE ( SUM ( t3[Value] ), FILTER ( ALL ( t3 ), t3[Category] = "C" ) )
        )
    RETURN
        _sum
    
  • Naveen29 smpa01  measure will work but here is another version of it

     

    % = 
    DIVIDE (
        CALCULATE ( SUM ('Table'[Value] ), KEEPFILTERS ( 'Table'[Category] <> "C" ) ),
        CALCULATE ( SUM ('Table'[Value] ),'Table'[Category] = "C" )
    )
    

     

     

    Follow us on LinkedIn and  to our YouTube channel

     

    Learn about conditional formatting at Microsoft Reactor

    My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • Naveen29's avatar
      Naveen29
      Helper II

      Thanks parry2k - This formula is working fine. However , there is another problem over here. My data is like below.  When we have break on the data ,this DAX is not working as expected.

      Ex: 

       

       Value
      Group 1\Category Name 
      A1
      B3
      C4
      Group2 \Category Name 
      X2
      Y3
      Z6

       

       Value%
      Group 1Total100%
      AA/C25%
      BB/C75%
      Group2Total100%
      XX/Z33%
      YY/Z50%
      Global TotalMeasure = (A+B+X+Y)/(C+Z)90%