cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Super User
Super User

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

View solution in original post

2 REPLIES 2
Super User
Super User

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

View solution in original post

franpimed Frequent Visitor
Frequent Visitor

Re: Create new column with the previous period value

Amazing. Works perfectly. Thanks for your great solution.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 284 members 2,621 guests
Please welcome our newest community members: