Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Calculated column Help

Hello Power Users,   I'm trying to calculated the following logic.  If the category column has "A" and "B" and i would like split the Value column By For "A" its 0.4*Value and for "B" its 0.2*Value...
  • v-yueyunzh-msft's avatar
    v-yueyunzh-msft
    3 years ago

    Hi, Anonymous 

    Thank you for your detailed explanation for your need .

    Here are the steps you can refer to :

    (1) My test is the same as yours.

    (2)We can click "New Column" and enter :

    Output = 
    var _number = [Booking Number] 
    var _category = DISTINCT(SELECTCOLUMNS( FILTER('Table','Table'[Booking Number]=_number) , "Category" , [Category]))
    var _exclude_count =COUNTROWS( EXCEPT( _category , {"A","B"}))
    var _cate = [Category]
    var _value =MAXX(FILTER( 'Table' , 'Table'[Booking Number] =_number ) , [Value])
    var _percentage =INTERSECT(_category , {"A","B"})
    var _per_value = IF( COUNTROWS( _percentage) =2 , 0.4 , IF( COUNTROWS(_percentage) =1 && COUNTROWS(INTERSECT({"A"},_percentage))=1 , 0.6 , 0.8))
     return
     IF([Expcnt] > 0 , [Expcnt] ,   IF(COUNTROWS(_category)<=3 , [Value1] ,   IF( _cate ="A", _value*0.4 ,IF( _cate ="B" , _value*0.2 ,DIVIDE( _per_value * _value,_exclude_count  )))))

    (3)Then we will meet your need:

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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