Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

IF statement combining multiple conditions from different columns and row just above

Hello All,

 

I am facing difficulties in translating the Excel formula below to Power Bi:

 

=IF(Q2=1;IF(M1="No";"No";L2);"NA")

 

For sensible reasons I cannot show a screenshot of data. However column Q is based on an IF statement and the output is either 1 or 2. Column M is a text column where output is "Yes" or "No" and column L is equal to a number (Average Time). As you can see in the formula, Q and L columns seek information in row 2 whereas column M seeks information in row 1. My data is layed out in a chronological way. Hence each row is connected to the above row and this is the reason why I need a formula to involve the current row with the one jsut above above. In excel it is very easy to combine multiple conditions of different format and located on different rows. However as I understood in Power Bi, we need to work with columns and formulas and cannot get around easily as in Excel and just select whichever cells in our formulas. 

 

I have explored several forums and videos and so far I know I must creat and index table (which I did) in order to refer to the row just above when including condition for column M. I aslo need to include functions such as Calcualte, Filter, Earlier, IF, SUM... However I have not find the right logic to develop my formula. I hope I have provided sufficient information to obtain help.

 

Thank you very much in advance.

  • Anonymous

     

    Your direction is correct. Somehow index is necessary. You need to use earlier to the pervious value or next value.

     

    Column = SUMX(FILTER('Sheet1 (2)','Sheet1 (2)'[index]=EARLIER('Sheet1 (2)'[index])-1),'Sheet1 (2)'[amount])

     

     

    The entire DAX should be something like below. You can modify by yourself. Thanks

     

    column =

    VAR M= SUMX(FILTER('Sheet1 (2)','Sheet1 (2)'[index]=EARLIER('Sheet1 (2)'[index])-1),'Sheet1 (2)'[amount])

    RETURN if(Q=1,IF(M="NO","No",L),"NA")

     

     

1 Reply

  • Anonymous

     

    Your direction is correct. Somehow index is necessary. You need to use earlier to the pervious value or next value.

     

    Column = SUMX(FILTER('Sheet1 (2)','Sheet1 (2)'[index]=EARLIER('Sheet1 (2)'[index])-1),'Sheet1 (2)'[amount])

     

     

    The entire DAX should be something like below. You can modify by yourself. Thanks

     

    column =

    VAR M= SUMX(FILTER('Sheet1 (2)','Sheet1 (2)'[index]=EARLIER('Sheet1 (2)'[index])-1),'Sheet1 (2)'[amount])

    RETURN if(Q=1,IF(M="NO","No",L),"NA")