Forum Discussion

Tybaal's avatar
Tybaal
Icon for Helper II rankHelper II
5 years ago
Solved

Calculate a simple percentage

Hello all,    I'm starting with Power BI and DAX and I try to compute a simple percentage but I have some weird result... I have a table and I like to see it like:  Product Price Price Paid ...
  • PhilipTreacy's avatar
    5 years ago

    Hi Tybaal 

    Download sample PBIX with solution

    SELECTEDVALUE gets the value on each row, try this

     

    % Paid = SELECTEDVALUE( 'Table'[Price Paid] ) / SELECTEDVALUE ( 'Table'[Price] )

     

     

    Or to avoid divide by zero problems, this will also work

    % Paid = DIVIDE( SELECTEDVALUE( 'Table'[Price Paid] ) , SELECTEDVALUE ( 'Table'[Price] ) )

     

    Regards

    Phil

  • Anonymous's avatar
    Anonymous
    5 years ago

    HI Tybaal,

    If you are work with measure expression, aggregate functions can be used to extract the current value.
    But when you work with calculated columns, if you not add any filter on these aggregate expressions they will summary whole column values instead of calculating on the current field value.

    I'd like to suggest you create calculated columns without aggregate function or create measure formulas that similar to 'PhilipTreacy' shared.

     

    % Paid = 'Table'[Price Paid] / 'Table'[Price]

     

    Regards,
    Xiaoxin Sheng