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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
hermesgoddess
Frequent Visitor

Add Custom Column with nested IF Not Working

I am trying to create a new column (two actually) that will return the total number of booked rooms Canceled from my database. The total number of booked rooms = number of rooms times number of nights - in my case [NumRms]*[Number of nights]. I also have a status column to find my canceled or no show rooms... [Status]="CXL" and [Status]="no show". If the status is anything except CXL or no show, I need the row to be "0". But my IF formula keeps giving me a Token Else expected. Not sure what I am missing:

 

Untitled picture.png

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @hermesgoddess,

 

In addition, you can also use DAX to add a new calculate column in your table under Modeling tab in this scenario. The formula below is for your reference. Smiley Happy

 

CANCELED =
IF (
    'Table1'[Status] = "CXL"
        || 'Table1'[Status] = "no",
    'Table1'[Num Rms] * 'Table1'[Number of nights],
    0
)

Note: Just replace 'Table1' with your table name.

 

modeling.PNG

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @hermesgoddess,

 

In addition, you can also use DAX to add a new calculate column in your table under Modeling tab in this scenario. The formula below is for your reference. Smiley Happy

 

CANCELED =
IF (
    'Table1'[Status] = "CXL"
        || 'Table1'[Status] = "no",
    'Table1'[Num Rms] * 'Table1'[Number of nights],
    0
)

Note: Just replace 'Table1' with your table name.

 

modeling.PNG

 

Regards

MarcelBeug
Community Champion
Community Champion

Try and replace "then if" by "or ".

 

Are you sure about the double quotes around the "0"?
I would expect just number 0, not text "0".

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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