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

How to Add Calculated Column that shows value of another column based on value of previous row

Hi everyone, 

i tried to look for a solution and cannot get it anywhere. 

I have a table and i am trying to add a column 'brand' which contains a specific value from the 'text' column.

The only way that the correct value is added is that the previous row contains the value "I'll need to know your brand first".  Not sure how to do this. Please see example below.

 

Table:

datesessionusertextExpected
brand
10/10/22 5:47Session1User1Welcome!  
10/10/22 5:48Session3User1Setup device 
10/10/22 5:48Session3User1I'll need to know your brand first. 
10/10/22 5:48Session3User1BrandBBrandB
10/10/22 5:49Session3User1Press keys 
10/10/22 5:52Session3User1Text sample 
10/10/22 5:52Session3User1Great! 
10/10/22 5:52Session4User1Setup device 
10/10/22 5:52Session4User1I'll need to know your brand first. 
10/10/22 5:53Session4User1BrandABrandA
10/10/22 5:53Session4User1Press keys 
10/10/22 5:53Session4User1Text sample 
10/10/22 5:53Session4User1Great! 
20/10/22 19:30Session6User2Welcome!  
20/10/22 19:30Session6User2I'll need to know your brand first. 
20/10/22 19:30Session6User2BrandCBrandC
20/10/22 19:30Session6User2Text sample 
20/10/22 19:31Session6User2Text sample 
20/10/22 19:31Session6User2Text sample 
20/10/22 19:31Session6User2Try again 
20/10/22 19:35Session7User2I'll need to know your brand first. 
20/10/22 19:35Session7User2BrandDBrandD

 

I hope you can help me out, i would much appreciate that.

Regards,

A

1 ACCEPTED SOLUTION
m_alireza
Solution Specialist
Solution Specialist

Hi @AndreaPiscitell ,


1) Create an index column in Power Query
2) Create this calculated column:

 VAR __Previous = MAXX(FILTER('Table',[index]<EARLIER('Table'[index])),[index])

    VAR __PreviousText = MAXX(FILTER('Table',[index]=__Previous),[text])
RETURN
    IF(__PreviousText ="I'll need to know your brand first.", 'Table'[text])


Sample output:
indexcolumn.png


I found an old post that sort of had a similar issue to yours: https://community.powerbi.com/t5/Desktop/Custom-column-evaluating-condition-of-previous-row/td-p/967...

Based on the discussions from there, I came up with the above. Hope it helps.








View solution in original post

1 REPLY 1
m_alireza
Solution Specialist
Solution Specialist

Hi @AndreaPiscitell ,


1) Create an index column in Power Query
2) Create this calculated column:

 VAR __Previous = MAXX(FILTER('Table',[index]<EARLIER('Table'[index])),[index])

    VAR __PreviousText = MAXX(FILTER('Table',[index]=__Previous),[text])
RETURN
    IF(__PreviousText ="I'll need to know your brand first.", 'Table'[text])


Sample output:
indexcolumn.png


I found an old post that sort of had a similar issue to yours: https://community.powerbi.com/t5/Desktop/Custom-column-evaluating-condition-of-previous-row/td-p/967...

Based on the discussions from there, I came up with the above. Hope it helps.








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.

Top Solution Authors