Forum Discussion

ccueto36's avatar
ccueto36
Frequent Visitor
7 years ago
Solved

Offsetting Calculated Column Rows

  Hi guys, I'm having a bit of a dilemma with generating a Calculated Column in DAX, the goal is to calculate Cal_charge+Amt column from the Excel table above. As you can see, the data on that ...
  • Zubair_Muhammad's avatar
    7 years ago

    ccueto36

     

    Try this calculated column

     

    Cal_charge+Amt =
    VAR temp =
        TOPN (
            2,
            FILTER ( Table3, [Month-Year] < EARLIER ( [Month-Year] ) ),
            [Month-Year], DESC
        )
    VAR temp1 =
        TOPN ( 1, temp, [Month-Year], ASC )
    RETURN
        IF ( COUNTROWS ( temp ) = 2, MINX ( temp1, [Sum of ChargeAmt] ) )
    
  • v-danhe-msft's avatar
    v-danhe-msft
    7 years ago

    Hi ccueto36,

    Based on my test, I have tried what Zubair suggested, it could work on my side, and you could also refer to my step:

    Sample data:

    Create a calculated column:

    Column 2 = var a=MONTH('Table3'[Month-Year])-2
    return CALCULATE(SUM(Table3[Sum of ChargeAmt]),FILTER('Table3',MONTH('Table3'[Month-Year])=a))

    Result(Column1 is the Zubair's function):

    You could also download the pbix to have a view, if it still could not work, could you please share the pbix if possible?

    https://www.dropbox.com/s/jjdh69fw2ipjbr4/Offsetting%20Calculated%20Column%20Rows.pbix?dl=0

     

     

    Regards,

    Daniel He