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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
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.