cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
franpimed Frequent Visitor
Frequent Visitor

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 filter. I have tried with previousmonth function, but I do not get the desired value.

 

PREVIOUS VALUE.PNG

 

Power BI File

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Nick_M New Contributor
New Contributor

Re: Create new column with the previous period value

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])
    )
)

Prev Month Calc Column.png

2 REPLIES 2
Nick_M New Contributor
New Contributor

Re: Create new column with the previous period value

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])
    )
)

Prev Month Calc Column.png

franpimed Frequent Visitor
Frequent Visitor

Re: Create new column with the previous period value

Amazing. Works perfectly. Thanks for your great solution.