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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
rob_vander2
Helper II
Helper II

create flag using complex if condition in power query

Hi All,

 

I have below dataset and required output in screenshot.

I would like to create Flag column in power query with below conditions
if Count is blank, all rows should be flagged as 1
if Count is not blank, I would like to Flag rows only for Ref 11,21 and 3.
for Ref 11,21 and 3, if Count is 2, Flag only Row where Type ="B" 
Screenshot 2025-02-24 at 16.37.40.png

2 ACCEPTED SOLUTIONS
Akash_Varuna
Super User
Super User

Hi @rob_vander2 ,You could achive this by custom column and if condition please try these 

  1. Add a Custom Column:
    • Go to the "Add Column" tab and select "Custom Column."
    • Formula:
      if [Count] = null then 1
      else if [Count] = 1 and ([Ref] = 11 or [Ref] = 21 or [Ref] = 3) then 1
      else if [Count] = 2 and [Type] = "B" then 1
      else null

  2. Filter the Rows:

    • After adding the Flag column, filter out rows where the Flag is null if you only want flagged rows in the final output.
      If this post helped please do give a kudos and accept this as a solution 
      Thanks In Advance

View solution in original post

SundarRaj
Super User
Super User

Hi @rob_vander2 , here's a solution you can check out. I'll attach a snippet of M code I used. Thanks

SundarRaj_0-1740421436609.png

 

Sundar Rajagopalan

View solution in original post

2 REPLIES 2
SundarRaj
Super User
Super User

Hi @rob_vander2 , here's a solution you can check out. I'll attach a snippet of M code I used. Thanks

SundarRaj_0-1740421436609.png

 

Sundar Rajagopalan
Akash_Varuna
Super User
Super User

Hi @rob_vander2 ,You could achive this by custom column and if condition please try these 

  1. Add a Custom Column:
    • Go to the "Add Column" tab and select "Custom Column."
    • Formula:
      if [Count] = null then 1
      else if [Count] = 1 and ([Ref] = 11 or [Ref] = 21 or [Ref] = 3) then 1
      else if [Count] = 2 and [Type] = "B" then 1
      else null

  2. Filter the Rows:

    • After adding the Flag column, filter out rows where the Flag is null if you only want flagged rows in the final output.
      If this post helped please do give a kudos and accept this as a solution 
      Thanks In Advance

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.