Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
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
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
@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"
@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 !
User | Count |
---|---|
141 | |
113 | |
104 | |
78 | |
64 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |