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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
svishwanathan
Helper III
Helper III

Help with getting value for previous period dax

Hello


I want to create a calculated column in my report.

I want that on any given row I should get the sum of sales from previous period. There are two conditions:

job id must match. the periods are not sequential so the row may contain data for november for the given id and the previous record for that job is in june

 

I am unable to sort the months with Job id.

 

Job id                 Month               Relative Month(from Jan2018)   Sales        Calculated Column

1                  November 2017        -2                                               4k                    8k

 

1                   June 2017                  -6                                              6k 

1                    August 2017              -4                                              8k                   6k

 

This helper column can help me to lookup the sales for that period and then I can compute how much the sales have increased or decreased since the last period

 

My issues: periods are not sequential....there are gaps (not necessarily selcted month-1)

I need to make sure ids match

 

I am unable to sort my months 

 

 

Regards
Swati

 

1 ACCEPTED SOLUTION

Hi,

 

Try this

 

=LOOKUPVALUE(Data[Sales],Data[Month],CALCULATE(MAX(Data[Month]),FILTER(Data,Data[Job ID]=EARLIER(Data[Job ID])&&Data[Month]<EARLIER(Data[Month]))),Data[Job ID],Data[Job ID])

 

Does this work?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

 

Here is the calculated column formula i have used

 

=LOOKUPVALUE(Data[Sales],Data[Month],CALCULATE(MAX(Data[Month]),FILTER(Data,Data[Job ID]=EARLIER(Data[Job ID])&&Data[Month]<EARLIER(Data[Month]))))

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ashish 

 

Thanks...I think the code breaks because for other job ids, the dates repeat.

 

For instance, say there are more records

 

ID   Month

2     01_nov-2017   

2       01-Aug-2017

Hi,

 

Try this

 

=LOOKUPVALUE(Data[Sales],Data[Month],CALCULATE(MAX(Data[Month]),FILTER(Data,Data[Job ID]=EARLIER(Data[Job ID])&&Data[Month]<EARLIER(Data[Month]))),Data[Job ID],Data[Job ID])

 

Does this work?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

LIFE SAVER, spent 3 hours trying to work this out

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks it works well

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @svishwanathan

 

Is your Month column a date time column, or is it Text?  

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hello

 

I would like to use my relative month column as the identifier...I can bring in the month as date but currently the month is identified by the relative value 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.