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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Compare two rows and return return the value

Hi All,

 

I have one probelm with comparing to rows in power.

 

excel formula is... IF(Part_Number_row2=Part_Number_row1 , Value_row1 , Value_row2)

 

if part number from row2 and row1 matched thes then want retun Value from row1 else value from row2.

 

My table look like below.

 

YearMonthPart NumberValue
2019Jan1012.914618
2019Jan1051.29267
2019Feb1051.273633
2019Mar1051.258231
2019Sep1075.208029
2019Oct1075.487181
2020Jan1051.254346
2020Feb1012.879371
2020Feb1052.281708
2020Apr1052.248105
2020Jun1055.377196
2020Sep1075.312167
2020Oct1075.316702
1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You will need to add an index column.

With the index column you can create a calculated cloumn.

Check the formula below.

Column = 
var column1 = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
var column2 = CALCULATE(MAX('Table'[Part Number]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
return
IF('Table'[Part Number]=column2,column1,'Table'[Value])

Result would be shown as below.

1.PNG

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

3 REPLIES 3
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You will need to add an index column.

With the index column you can create a calculated cloumn.

Check the formula below.

Column = 
var column1 = CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
var column2 = CALCULATE(MAX('Table'[Part Number]),FILTER('Table','Table'[Index]=EARLIER('Table'[Index])-1))
return
IF('Table'[Part Number]=column2,column1,'Table'[Value])

Result would be shown as below.

1.PNG

 

Best Regards,

Jay

 

Community Support Team _ Jay Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@Anonymous , better you have date column or create one like suggested

date = "1-"&[Month] & "-"&[Year] // Change data type to Date

New column
last date = maxx(filter(table,[date] <earlier([date]) && [Part Number] =earlier([Part Number])),[date])
last value = maxx(filter(table,[date] =earlier([last date ]) && [Part Number] =earlier([Part Number])),[value])

 

You can use last value and compare value and use

Anonymous
Not applicable

I am getting an error if we have same date in two consecutive rows.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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