Forum Discussion

Meghbajaj's avatar
Meghbajaj
Frequent Visitor
3 years ago
Solved

Percentage Change and Value Difference

Hi Everyone, I am trying to calculate Percentage Change and Value Difference group by ID in the Power BI report. Please suggest the optimal way to do it. Thanks a lot.   Original Table: ID Sal...
  • FreemanZ's avatar
    3 years ago

    hi Meghbajaj 

    try to add two columns like this:

    Salary Change 2 = 
    VAR _id = [ID]
    VAR _date = [Effective Date]
    VAR _table =
    FILTER(TableName, TableName[ID]=_id)
    VAR _datepre =
    MAXX(
        FILTER(_table, TableName[Effective Date]<_date),
        TableName[Effective Date]
    )
    VAR _salarypre =
    MINX(
        FILTER(_table, TableName[Effective Date]=_datepre),
        TableName[Salary]
    )
    RETURN
    IF( _salarypre<>BLANK(), [Salary] - _salarypre)
    
    Percent Change  2 = 
    VAR _id = [ID]
    VAR _date = [Effective Date]
    VAR _table =
    FILTER(TableName, TableName[ID]=_id)
    VAR _datepre =
    MAXX(
        FILTER(_table, TableName[Effective Date]<_date),
        TableName[Effective Date]
    )
    VAR _salarypre =
    MINX(
        FILTER(_table, TableName[Effective Date]=_datepre),
        TableName[Salary]
    )
    RETURN
    IF( _salarypre<>BLANK(), DIVIDE( [Salary] - _salarypre, _salarypre))

     

    it worked like this: