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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
C4L84
Advocate II
Advocate II

Addcolumn with if statement

Hi community,

 

I'm looking for some help with an ADDCOLUMN expression.

 

I need to add a new column called "RevenueType" in the BookingStatus table which groups BookingCodes A, R, H and CX as "Confirmed revenue" with all remaining codes as "Provisional".

 

Here is a pbix example.

 

I've got as far as creating the if statement: 

RevenueType = IF(MIN('Booking statuses'[BookingCode]) in {"A","R","H","CX"}, "Confirmed revenue", "Provisional")
 
But can't figure out how to add this column to the table as I am getting and error that reads "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."
 
C4L84_0-1659431751488.png

 

It should be noted that this has to be a DAX expression and the data cannot be modified in the query editor.

 

I'm hoping someone in the community can help as I've been stuck on this for some time!

8 REPLIES 8
Vasuno1
Frequent Visitor

I am not sure that you need to use the addcolumn function for this but if you really need to let me know.

 

I achieved what you are looking for by adding a new column as shown below:

Vasuno1_1-1689106466161.png

 

Then I inputted the following in the formula bar:

RevenueType = IF('Booking statuses'[BookingCode] in {"A","R","H","CX"},"Confirmed Revenue", "Provisional")
RevenueType = IF('Booking statuses'[BookingCode] in {"A","R","H","CX"},"Confirmed Revenue", "Provisional")
 
See result below:

 

Vasuno1_0-1689106426924.png

 

SpartaBI
Community Champion
Community Champion

@C4L84 do you mean like this?

SpartaBI_0-1659442841376.png

 

RevenueType = IF('Booking statuses'[BookingCode] in {"A","R","H","CX"}, "Confirmed revenue", "Provisional")

 


Here is a link to download the file with the solution:
Addcolumn with if statement 2022-08-02.pbix


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Thanks for replying @SpartaBI 

 

I need to add a new column to the BookingStatus table using DAX, which uses the IF statement.

SpartaBI
Community Champion
Community Champion

@C4L84 i'm confused 😁 isn't it what I sent you?

@SpartaBI I need to specifically use the ADDCOLUMN funtion, something like this:

 

RevenueType =

ADDCOLUMNS('Booking statuses',"RevenueType",

IF(MIN('Booking statuses'[BookingCode]) in {"A","R","H","CX"}, "Confirmed revenue", "Provisional")
)
 
But I am getting this error message: 
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
Vasuno1
Frequent Visitor

@C4L84  - Sorry I didn't realize that you reiterated your absolute need to use the ADDCOLUMNS function (nor did I notice that someone already posted the exact solution I did 😞)

 

@C4L84  / @Ivn_rmr  - I used the below formula to create the table using the ADDCOLUMNS function:

 

RevenueType = ADDCOLUMNS('Booking statuses',"RevenueType",IF('Booking statuses'[BookingCode] in {"A","R","H","CX"},"Confirmed Revenue", "Provisional"))

Hi, I know it has been a while since you posted your question. Did you come across with any solution? I am having the same issue.

Hi @Ivn_rmr 
Please explain your issue perhaps I can help. 

With regard to this particular question, I can see that @SpartaBI already provided a workable solution. However, the request of using ADDCOLUMNS function as per @C4L84 is not clear as ADDCOLUMNS returns a table not a scalar value. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors