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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
e77948
Regular Visitor

How do I write an IF then formula

I have a table and I need to show the data depending upon one column, I am trying to write a measure that will show the number of work items if that colu

2 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @e77948 ,

 

In Power Query, it's like this:

if somethingIsTrue
then doThis
else if somethingElseIsTrue
then doThisThingInstead
else doThisThing

 

In DAX, it's like this:

IF(
    somethingIsTrue,
    doThis,
    doThisThingInstead
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

 

Ah, ok, my bad. Text functions don't skip blanks.

Try this one:

if [Tags] = null then "Primary"
else if Text.Contains([Tags], "Secondary") then "Secondary"
else "Primary"

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @e77948 ,

 

Sorry for that the information you have provided is not making the problem clear to me.

 

Can you please share more details (your tables, your problems, the expected output) to help us clarify your scenario? Or try methods provided by @BA_Pete .

 

Refer to:

How to Get Your Question Answered Quickly - Microsoft Power BI Community

How to provide sample data in the Power BI Forum - Microsoft Power BI Community

 

Best Regards,
Eyelyn Qin

if Text.Contains([Tags], "Secondary") then "Secondary" else "Primary" or if isBlank([Tags], "Primary") 

Hi @e77948 ,

 

'isBlank' isn't an M language function, it's a DAX function.

If you can describe the behaviour that you're trying to achieve, I can write the correct M code syntax for you.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




I want the custom column to say "Primary" if the column "Tags", does not contain the word "Secondary",  or if the "Tags" column is blank, and I want the new column to say "Secondary" if the "Tags" column, contains the word "Secondary".

 

Cool. Try this in a new custom column:

if Text.Contains([Tags], "Secondary") then "Secondary" else "Primary"

 

Based on your requirement, we don't need to specify anyhting for a blank [Tags] value, as we just pass anything that doesn't contain "Secondary" as a "Primary" output.

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




I get errors for the 25 rows that are blank when I use that query, 

 

Ah, ok, my bad. Text functions don't skip blanks.

Try this one:

if [Tags] = null then "Primary"
else if Text.Contains([Tags], "Secondary") then "Secondary"
else "Primary"

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




BA_Pete
Super User
Super User

Hi @e77948 ,

 

In Power Query, it's like this:

if somethingIsTrue
then doThis
else if somethingElseIsTrue
then doThisThingInstead
else doThisThing

 

In DAX, it's like this:

IF(
    somethingIsTrue,
    doThis,
    doThisThingInstead
)

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Please refer to - How to Get your Question Answered Quickly - https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

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.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.