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

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

Reply
LearningBI1986
Frequent Visitor

Simple if-then statement DAX

Hi guys,

Can I get help with a quick, if-then statement, with the following criteria?

If flight # = 832, flying on Tues, Wed, Thurs, and Fri (Days 2, 3, 4, 5), then seats = 53.

 

I have this, and am getting an error of "token literal expected:"
if [#"Flight #"]="832" && ([Day of Week]=2 || [Day of Week]=3 || [Day of Week]=4 || [Day of Week]=5) then [Seats]="53" else 0

 

Can't seem to figure out my error.

2 ACCEPTED SOLUTIONS
BA_Pete
Super User
Super User

Hi @LearningBI1986 ,

 

Ok. Based on the error you're getting, it looks like you're trying to do this in Power Query. If so, then it's not DAX you need, it's M, and you appear to have mixed both languages in your statement.

The if..then structure in M looks like this:

if (something and somethingElse) or anotherThing
then doThisThing
else doThisOtherThing

 

So, your example would look something like this:

if [#"Flight #"]="832" and List.Contains({2,3,4,5}, [Day of Week])
then 53
else 0

 

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

Anonymous
Not applicable

Hi @LearningBI1986 ,

 

Pete provides m-codes that you can use in the PowerQuery editor to add a custom column.

Add a custom column - Power Query | Microsoft Learn

 

For DAX, please try:

Seats = IF(
    'TableName'[Flight #] = 832 && 'TableName'[Day of Week] IN {2,3,4,5,6},
    53,
    0
)

IF - DAX Guide

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
BA_Pete
Super User
Super User

Hi @LearningBI1986 ,

 

Ok. Based on the error you're getting, it looks like you're trying to do this in Power Query. If so, then it's not DAX you need, it's M, and you appear to have mixed both languages in your statement.

The if..then structure in M looks like this:

if (something and somethingElse) or anotherThing
then doThisThing
else doThisOtherThing

 

So, your example would look something like this:

if [#"Flight #"]="832" and List.Contains({2,3,4,5}, [Day of Week])
then 53
else 0

 

Pete



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

Proud to be a Datanaut!




Thank you! I am fairly new to this, so I understand what you are saying now. Thanks again.

Anonymous
Not applicable

Hi @LearningBI1986 ,

 

Pete provides m-codes that you can use in the PowerQuery editor to add a custom column.

Add a custom column - Power Query | Microsoft Learn

 

For DAX, please try:

Seats = IF(
    'TableName'[Flight #] = 832 && 'TableName'[Day of Week] IN {2,3,4,5,6},
    53,
    0
)

IF - DAX Guide

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Kudoed Authors