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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

IF formula taking into account a condition from cell located in row above.

Hi All,

 

I am relatively new to Power Bi and I am struggling into creating an IF formula with multiple conditions where one of the conditions is to consider a value located in the row above. I saw in one of the discussions that I should create and Index column and include it in my IF formula but I am not to sure how it works.

 

My formula so far looks like this: Answer= IF('Table1'[Response]="1" &&... Here I would like to add the other condition which refers to the cell in the row jsut above. Then based on both these conditions the return value would be equal to the value of a particular cell within the same row. 

 

Hope you can help me and thank you in advance.

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@Anonymous,

 

Based on your description, suppose your table is like below and you want to achieve the value in above row which meets your requirement.

2.PNG 

 

Yes, you need to create an index column first, click query editor-> add columns-> index column, then apply and close query editor. Create a calculate column using DAX like pattern below:

Answer = 
VAR index_above_row = Table1[Index]
RETURN
    IF (
        Table1[Response] = 1
            && Table1[Response]
                = CALCULATE (
                    MAX ( Table1[Response] ),
                    FILTER ( Table1, Table1[Index] = index_above_row - 1 )
                ),
        CALCULATE (
            MAX ( Table1[Value] ),
            FILTER ( Table1, Table1[Index] = index_above_row - 1 )
        ),
        "Not Found"
    )

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

View solution in original post

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

@Anonymous,

 

Based on your description, suppose your table is like below and you want to achieve the value in above row which meets your requirement.

2.PNG 

 

Yes, you need to create an index column first, click query editor-> add columns-> index column, then apply and close query editor. Create a calculate column using DAX like pattern below:

Answer = 
VAR index_above_row = Table1[Index]
RETURN
    IF (
        Table1[Response] = 1
            && Table1[Response]
                = CALCULATE (
                    MAX ( Table1[Response] ),
                    FILTER ( Table1, Table1[Index] = index_above_row - 1 )
                ),
        CALCULATE (
            MAX ( Table1[Value] ),
            FILTER ( Table1, Table1[Index] = index_above_row - 1 )
        ),
        "Not Found"
    )

Capture.PNG 

 

Community Support Team _ Jimmy Tao

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

Anonymous
Not applicable

Yes this is exactly the logic I need. Thank you so much!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.