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.
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 !
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |