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

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.

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@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")

 

 

c1.JPG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
ryan_mayu
Super User
Super User

@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")

 

 

c1.JPG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.