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
MyWeeLola
Regular Visitor

Scalar error in addcolumns

Good morning

 

I have unpivoted a table which gives me an ID column and an Attribute column. I have a lot of attributes to display, so I thought I would try to group them to make it easier for the user.

 

My thought was to create a calculated column that would apply my "grouped" titles to the attributes, however, I'm struggling to get the code I need.

 

MyWeeLola_0-1713167178158.png

In my example, I want the calculated column to apply, "Car, Plane, Ship"  to the relevant attribute

 

I was thinking

 

Vehicle = 

union(

addcolumns(

//goes wrong here

'mytable',"Type",'mytable'[attribute] = "Dodge","Car"),
//other selections

Dax is telling me that I have messed up with no scalar expression certified.

I think I'm trying to return the complete table, however I'm unsure how to this without "if then" statements

 

as a second question, in the example, if I specified which are ships and planes, could I make a default selection which makes the rest "cars"?

 

I look forward to hearing back.

 

Lola 

 

1 ACCEPTED SOLUTION
v-jingzhan-msft
Community Support
Community Support

Hi @MyWeeLola 

 

The first method is to right click on the Attribute column and select New group. This feature can help you group values in this column through GUI easily and give you the group column you want. Use grouping and binning in Power BI Desktop - Power BI | Microsoft Learn

vjingzhanmsft_1-1713251650579.pngvjingzhanmsft_0-1713251620148.png

 

The second method is to use DAX to create a calculated column

Column = SWITCH(TRUE(),
'Table'[Attribute] IN {"Jet","Seaplane","Glider"}, "Plane",
'Table'[Attribute] IN {"Titanic"}, "Ship",
"Car"
)

vjingzhanmsft_2-1713251984580.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

View solution in original post

2 REPLIES 2
v-jingzhan-msft
Community Support
Community Support

Hi @MyWeeLola 

 

The first method is to right click on the Attribute column and select New group. This feature can help you group values in this column through GUI easily and give you the group column you want. Use grouping and binning in Power BI Desktop - Power BI | Microsoft Learn

vjingzhanmsft_1-1713251650579.pngvjingzhanmsft_0-1713251620148.png

 

The second method is to use DAX to create a calculated column

Column = SWITCH(TRUE(),
'Table'[Attribute] IN {"Jet","Seaplane","Glider"}, "Plane",
'Table'[Attribute] IN {"Titanic"}, "Ship",
"Car"
)

vjingzhanmsft_2-1713251984580.png

 

Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

@v-jingzhan-msft 

Perfect, thank you for this.

Lola

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.