Forum Discussion

lastnn30's avatar
lastnn30
Post Patron
3 years ago
Solved

Functions for a calculated column

Hi

I want to create a calculated column for this table. I have 2 columsn and I want to add them and out the result in the calculated column.  If I write this formula

 

= RoundTb[Amount] + RoundTb[bonus]

 

Everything is fine, but if i write this

 

=Sum(RoundTb[Amount] + RoundTb[bonus])

 

I get the message below. Does that mean for New Column, I can not use DAX function, only formulas? Thank you very much.

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi lastnn30 ,

     

    The SUM() function can contain only one column name.

    The SUM() function adds up the values of the fields in the calculated column.

    If you still want to use the SUM() function to return the value of each row, you can write like the following.

    Column = CALCULATE(SUM('RoundTb'[Amount]),FILTER('RoundTb',[Amount]=EARLIER('RoundTb'[Amount])&&[bouns]=EARLIER(RoundTb[bouns])&&[item]=EARLIER(RoundTb[item])))

    In addition to the calculated column, there is also a measure that gives the result based on the context of the row.

    Then measure and calculated columns sometimes return different results because the measure and the calculated column has a different row context. 

    Calculated Column and Measure in Power BI (powerbiconsulting.com)

     

     

    Best Regards,

    Stephen Tao

     

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

     

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi lastnn30 ,

     

    The SUM() function can contain only one column name.

    The SUM() function adds up the values of the fields in the calculated column.

    If you still want to use the SUM() function to return the value of each row, you can write like the following.

    Column = CALCULATE(SUM('RoundTb'[Amount]),FILTER('RoundTb',[Amount]=EARLIER('RoundTb'[Amount])&&[bouns]=EARLIER(RoundTb[bouns])&&[item]=EARLIER(RoundTb[item])))

    In addition to the calculated column, there is also a measure that gives the result based on the context of the row.

    Then measure and calculated columns sometimes return different results because the measure and the calculated column has a different row context. 

    Calculated Column and Measure in Power BI (powerbiconsulting.com)

     

     

    Best Regards,

    Stephen Tao

     

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

     

    • lastnn30's avatar
      lastnn30
      Post Patron

      Thanks a lot for your reply. It did not work! please see the screenshot below: