Forum Discussion

franpimed's avatar
franpimed
Frequent Visitor
7 years ago
Solved

Create new column with the previous period value

Hello, I'm new in power bi and I'm trying to create a new column that allows me to get the value of the previous month, but I have several columns in the data and I don“t know how to perform the fil...
  • Anonymous's avatar
    Anonymous
    7 years ago

    You can use the following code to generate a new column:

    Column = 
    VAR __CurrentPeriod = Test[PERIOD D/M/YY]
    var __CurrentCountry = Test[COUNTRY]
    var __CurrentProduct = Test[PRODUCT]
    var __CurrentActivity = Test[ACTIVITY]
    RETURN
    
    CALCULATE(
        SUM( Test[CANTIDAD] ),
        FILTER(
            Test,
            Test[COUNTRY] = __CurrentCountry
            && Test[PRODUCT] = __CurrentProduct
            && Test[ACTIVITY] = __CurrentActivity
            && __CurrentPeriod = NEXTMONTH(Test[PERIOD D/M/YY])
        )
    )