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
v-power
Frequent Visitor

Creating a Prior Month Column in Power BI

Hello All, 

 

I have a table like below. I would like to create another column for Prior Month which would display previous months value as a column. 

 

KPI NameMonthValue
KPI 17/31/2018100.00
KPI 18/31/201899.94
KPI 19/30/201899.97
KPI 110/31/2018100
KPI 111/30/201899.99
KPI 112/31/201899.86
KPI 11/31/201999.90
KPI 12/28/2019100

 

Output like this:

 

KPI NameMonthValuePrior Month
KPI 17/31/2018100.000
KPI 18/31/201899.94100
KPI 19/30/201899.9799.94
KPI 110/31/201810099.97
KPI 111/30/201899.99100
KPI 112/31/201899.8699.99
KPI 11/31/201999.9099.86
KPI 12/28/201910099.9

 

 I used the following DAX query and it doesnt seem to work. Any help would be much appreciated.

 


Last Month = CALCULATE(FIRSTNONBLANK(Table1[Value],Table1[Value]),DATEADD(Value[Month],-1,MONTH))

1 ACCEPTED SOLUTION

Hi,

I'm sure there are a few solutions to this. 

If we use DATEADD in a measure like

 

Prev Month Sale = CALCULATE(SUM(Table1[Value]), DATEADD(Table1[Month],-1,MONTH))
 
The measure will return some correct values but some blanks.

DATEADD won't always work in this example because the dates it works out have to exist in the table.  Let's take one case from the table - '30 sept 2018', subtract 1 month from this and we get '30 Aug 2018' (and that date doesn't exist in the table)

 

What we need is a measure like this :

 

Prev Month Sale 2 = CALCULATE(SUM(Table1[Value]), PREVIOUSMONTH(Table1[Month]))

View solution in original post

7 REPLIES 7
BIWorker10AW
Helper I
Helper I

Is there any way we could do this in Power Query?

v-power
Frequent Visitor

Hello @BobiRussell 

 

Thanks for the response. I have both of the values in same table. And "Value" is not a measure I calculated. It is part of the original table. 

 

 

Oka V-Power,

 

So this is what I've used

 

Gross Revenue LM = CALCULATE(
[Gross Revenue], DATEADD( facts_Transactional[Invoice Date], -1, MONTH ) )
 
Gross Revenue LM is a measure that I added to my "Key Measures" group. My Gross Revenue is a field that I created a measure but I could have used List Revenue that is already in the tabel like yours.
My invoice date is in a different table so i had to reference the table name but it everything is in one table and want to add a column then you wont need the references the various tables.
 
Hope that work for you!

Thank you. I tried to search for the "value" field on my table1 using the calculate but it only lists the calculated measures I had created. Existing fields in the table dont show up for some reason.

Hi,

I'm sure there are a few solutions to this. 

If we use DATEADD in a measure like

 

Prev Month Sale = CALCULATE(SUM(Table1[Value]), DATEADD(Table1[Month],-1,MONTH))
 
The measure will return some correct values but some blanks.

DATEADD won't always work in this example because the dates it works out have to exist in the table.  Let's take one case from the table - '30 sept 2018', subtract 1 month from this and we get '30 Aug 2018' (and that date doesn't exist in the table)

 

What we need is a measure like this :

 

Prev Month Sale 2 = CALCULATE(SUM(Table1[Value]), PREVIOUSMONTH(Table1[Month]))

Thank you so much. This worked.

BobiRussell
Frequent Visitor

Hi v-power

 

See if this works.

 

Table Name = should refer to the table that you have the revenue or in your case "Value". The "Table Name[Month]" is your date table either in your facts table or Calendar table. This work for my reporting and should work?

 

Prior Month = CALCULATE(Table Name[Value], DATEADD(Table Name[Month], -1, MONTH ) )

 

Best,

Bobi

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.