Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
franpimed
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
Anonymous
Not applicable

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

3 REPLIES 3
UK06B1
Helper II
Helper II

Hello I was trying to use the attached thread to solve a similar issue - i cannot get the previous month column to return the previous periods hours (week ending - are weekly periods - link to the week column). see screen shot below which has the formula + the table view. 

 

Therefore for a given employee and a given time stamp and a given week - i would like to return the previous month value so that i can then see on a graph later the difference - or the monthly value - note my data is cumulative data. 

 

The screen shot below shows the current formula i have - 

Any help would be greatly appreciated. 

 

UK06B1_0-1624540298518.png

 

Anonymous
Not applicable

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

Amazing. Works perfectly. Thanks for your great solution.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.