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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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!:
Mastering Power BI 2nd Edition

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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