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
Jlbaenlo
Frequent Visitor

Extra column in table, populated by offseting by X months another existing column from this table

Hello,

I would need some guidance on the following problem

I have a table

Product - Country - Date - KPI1

A-C1-Jan2020- 60

A-C1-Feb2020-70

A-C1-Mar2020-50

I would like to add an extra column which would put for each Product-Country-Date the KPI1 of the previous month date for that same product-country (and blank if no record found)

Product - Country - Date - KPI1 - Newcol

A-C1-Jan2020- 60- Blank

A-C1-Feb2020-70- 60

A-C1-Mar2020-50-70

in the example above I put 60 in the new column as it was the value of the previous month, etc...

I need to formula generic enough so I can decide how many months back I want to take the value.

 

Many thanks,

BR,

Jean-Luc

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hi @Jlbaenlo ,

In my opinion,  @amitchandak 's method is the simplest and most efficient.

If he answered your question, please mark his post as a solution.

 

Best regards,

Eyelyn Qin

Greg_Deckler
Super User
Super User

@Jlbaenlo - You will need a true Date column or you will need an Index column or you will need a big nasty SWITCH statement in order to figure out your previous month. If Date column your previous month is:

Newcol =
  VAR __Product = [Product]
  VAR __Country = [Country]
  VAR __PreviousMonth = EOMONTH([Date],-1)
  VAR __PreviousDate = DATE(YEAR(__PreviousMonth),MONTH(__PreviousMonth),1))
  VAR __Previous = MAXX(FILTER('Table',[Product]=__Product && [Country]=__Country && [Date]=__PreviousDate),[KPI1]

 For Index and SWITCH, same basic thing just how you arrive at your "__PreviousDate"


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@Jlbaenlo , I am assuming date is date not month year, else create a date

a new column
sumX(filter(Table, [Product] =earlier([Product]) && [Country] = earlier([Country]) && eomonth([Date],0) =eomonth(earlier([Date]),-1)),[KPI1])

 

or

 

sumX(filter(Table, [Product] =earlier([Product]) && [Country] = earlier([Country]) && eomonth([Date],0) =eomonth(earlier([Date]),-1)),earlier([KPI1]))

Many thanks, it worked brilliantly !

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.