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
Anonymous
Not applicable

Help with Formula - Identify Previous Product by Year

Hello Community, 

 

Can you please help me writing a following DAX  Column .  I have following calculated column which identify previous product by Date . I need it by Year. 

 

Customer ID |      DATE               |  Product  | Previous Product 

   1                      1/Jan/2020           A                   -

   1                       2/ Feb/ 2020       B                   A

   1                      13 / Jan/ 2021      B                   -
   1                      14 / Feb/ 2021     A                  B

I tried using folloing formula but it is by date : I need it by year

 

Previous Product =
VAR MAX_Date =
CALCULATE (
MAX( 'Master_Table'[Dates]) ,
ALLEXCEPT('Master_Table','Master_Table'[ID] ,'Master_Table'[Dates]))

VAR PreviousDate =
CALCULATE(
MAX ('Master_Table'[Dates] ) ,
ALLEXCEPT( 'Master_Table' ,'Master_Table'[ID]) , 'Master_Table'[Dates]< MAX_Date)
 

VAR PREV_PROD =
CALCULATE(
MAX ( 'Master_Table'[Product] ) ,
ALLEXCEPT( 'Master_Table' ,'Master_Table'[CI]) , 'Master_Table'[Dates]= PreviousDate )


RETURN
PREV_PROD
1 ACCEPTED SOLUTION

@Anonymous  sorry my bad, try this

 

_prevProd = calculate(max('Table'[Product]),FILTER('Table','Table'[CustID]=EARLIER('Table'[CustID])&&'Table'[_year]=EARLIER('Table'[_year])&&'Table'[Date]<EARLIER('Table'[Date])))

 

 

smpa01_0-1639759661602.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

@Anonymous  try this

_prevProd = MINX(FILTER('Table','Table'[CustID]=EARLIER('Table'[CustID])&&'Table'[_year]=EARLIER('Table'[_year])&&'Table'[Date]<EARLIER('Table'[Date])),'Table'[Product])

 

smpa01_0-1639757355360.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Hi @smpa01 ,

 

Thankyou so much for the reply. 

 

I am looking continuous previous product.  The code you send is producing  only  first previous product in year.

 

Channa_0-1639759201918.png

 

@Anonymous  sorry my bad, try this

 

_prevProd = calculate(max('Table'[Product]),FILTER('Table','Table'[CustID]=EARLIER('Table'[CustID])&&'Table'[_year]=EARLIER('Table'[_year])&&'Table'[Date]<EARLIER('Table'[Date])))

 

 

smpa01_0-1639759661602.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01  Thank you so much! It is really helpful 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.