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

Lookup value of previous month in the same table in Power Query

Hi,

 

https://community.powerbi.com/t5/Desktop/Lookup-for-the-value-of-previous-month-in-the-same-table/td...

 

Hope everyone is well. I am trying to achieve a solution similar to the above thread but using Power Query instead of DAX. I have appended multiple extracts of the same data in the same structure. Each extract has a timestamp column displaying the extraction date.

 

I want to create a custom column using Power Query which displays the same value but for the previous month. Example below:

 

Example.PNG

 

Best regards,

Ami

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @amikhan12345 ,

you must group on "Customer" and return all values from your table. Then a apply a function that returns the previous row value like so: Fast and easy way to reference previous or next rows in Power Query or Power BI – The BIccountant 

If you need help applying this, please paste sample data that can easily used like described here:

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
amikhan12345
Frequent Visitor

Thank you @amitchandak and thank you @ImkeF for the Power Query solution. The additional video on your website on was very helpful.

ImkeF
Super User
Super User

Hi @amikhan12345 ,

you must group on "Customer" and return all values from your table. Then a apply a function that returns the previous row value like so: Fast and easy way to reference previous or next rows in Power Query or Power BI – The BIccountant 

If you need help applying this, please paste sample data that can easily used like described here:

https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

amitchandak
Super User
Super User

@ImkeF , Can you help on this.

 

@amikhan12345 , check with M experts . In Dax code can be

var _max = maxx(filter(Table,[customer] =earlier([customer) && [recorded timestamp] <earlier([recorded timestamp]) ),[recorded timestamp])
return
maxx(filter(Table,[customer] =earlier([customer) && [recorded timestamp] =_max ),[status])

Hi @amitchandak 

 

I am trying to implement this formula as a DAX calculated column but the formula is not returning any fields for Customer. When you have a moment could you refine the syntax for me? (I appreciate you probably improvised this measure as an example)Example.PNG

 

Ami

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.