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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Mars3442
Helper I
Helper I

Lookup past 1 month and past 2 month data from different table

Hi all,

I want to look up data from different table

Example of Stock table

Mars3442_0-1697448638495.png

Example Sales Table

Mars3442_1-1697448665113.png

Expected table

Mars3442_2-1697448685051.png

Stock January 2023 add column past 1 month sales = Sales December 2022

Stock February 2023 add column past 1 month sales = Sales January 2022

All of Stock March 2023 add column past 1 month sales = Sales February 2022

 

Stock January 2023 add column past 2 month sales = Sales November 2022

Stock February 2023 add column past 2 month sales = Sales December 2022

All of Stock March 2023 add column past 2 month sales = Sales January 2022

 

Please help me to solve this problem using DAX or M Language

Thank you..

4 REPLIES 4
Mars3442
Helper I
Helper I

I try to use this DAX but it not works
 
Measure = CALCULATESUMX( 'SALES' 'SALES' [SALES]), DATESINPERIOD'SALES' [Date]MAX' STOCK' [Date]), -1MONTH))
 
Measure = CALCULATESUMX( 'SALES' 'SALES' [SALES]), DATEADD'SALES' [Date]-1MONTH))
 
AilleryO
Memorable Member
Memorable Member

Hi,

Do you have a Date Table ? If yes it should be easy with CALCULATE + DATEADD functions (with -1 MONTH and -2 MONTH), or maybe DATESINPERIOD.

Then finally your visual will be build with the dates coming from the date table, this one being related to the 2 other tables (sales and stock).

Hope it helps otherwise tell us what's not clear.

Yes I have date table like this

Date

1 Dec 2022

1 Nov 2022
1 Jan 2023
1 Feb 2023
1 March 2023
8 March 2023
15 March 2023

 

Please help me with the DAX or using power query

Thankyou

Hi,

You cannot have a "real" date table being like that.

A date table got (at least) a column with dates, all dates being uniques and contiguous (1st jan, 2nd jan, 3rd jan....), more details :

https://learn.microsoft.com/en-us/power-bi/guidance/model-date-tables

It must be marked as date table (right click on table), and related to fact table

Without a proper date table, you might encounter many results being empty (null).

Please read above informations and add to your model a "real" date table and then it should work easily.

Let us know

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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