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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
makcim392
Advocate I
Advocate I

Is there a way to execute an if statement row by row?

Hi everyone,

 

I'm trying to get the top 20 percent of some clients. I'd like to create a filter which looks at the client data, if they are on the top 20 percent, write the value, if not, leave it blank. So that then I can filter in a table, summing the rows that have data (leaving the blank values outside the calculation). All these values summed (displayed in a row), are compared against some dates (which are in columns, the dates I mean)

 


Problem is that I cannot execute an if statement row by row. I'm comparing 2 values from the same row as an assertion, and leaving it blank if its lower than the other value, otherwise copy the value from one of the values I'm comparing in the statement. 

I'm also having issues with the last part, for some reason power bi isn't suggesting the column I want to use for copying the value. 

 

 

Thanks!

2 ACCEPTED SOLUTIONS
VasTg
Memorable Member
Memorable Member

@makcim392 

 

Yes.. Two options.

 

1. Create a conditional column or custom column in Query editor(Transform data )

 

or 

2. Create a calculated column and write DAX

image.png

If it helps, mark it as a solution

Kudos are nice too

Connect on LinkedIn

View solution in original post

v-yuta-msft
Community Support
Community Support

@makcim392 ,

 

If you want to achieve this in power query, you can create a custom column in query editor, you can refer to doc:

https://docs.microsoft.com/en-us/power-bi/desktop-add-custom-column

 

In you want to add a new column in table using dax, please create a calculate column using dax function IF():

https://docs.microsoft.com/en-us/dax/if-function-dax

 

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

4 REPLIES 4
v-yuta-msft
Community Support
Community Support

@makcim392 ,

 

If you want to achieve this in power query, you can create a custom column in query editor, you can refer to doc:

https://docs.microsoft.com/en-us/power-bi/desktop-add-custom-column

 

In you want to add a new column in table using dax, please create a calculate column using dax function IF():

https://docs.microsoft.com/en-us/dax/if-function-dax

 

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.

mwegener
Most Valuable Professional
Most Valuable Professional

Hi @makcim392 ,

 

check this out.

SUMX

Returns the sum of an expression evaluated for each row in a table.

https://docs.microsoft.com/en-us/dax/sumx-function-dax

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast - Power BI Tutorials


amitchandak
Super User
Super User

Refer

https://www.burningsuit.co.uk/blog/2019/05/find-top-or-bottom-n-percent-dax/

https://community.powerbi.com/t5/Desktop/Top-N-percent-filter/td-p/682552

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
VasTg
Memorable Member
Memorable Member

@makcim392 

 

Yes.. Two options.

 

1. Create a conditional column or custom column in Query editor(Transform data )

 

or 

2. Create a calculated column and write DAX

image.png

If it helps, mark it as a solution

Kudos are nice too

Connect on LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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