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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.