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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
henryzf
Frequent Visitor

Power BI power query how to add a new column based on other columns value

I want to create a new column from Power query that if any other columns contain value "异常"then return value in new column "异常" else "正常". I have used List.ComtainsAny but have error.

henryzf_0-1720774705619.png

henryzf_1-1720774721327.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @henryzf 

 

You only need to make a small modification to @dufoq3 's solution like below

= Table.AddColumn(#"Previous Step", "Custom", each if List.Contains(Record.ToList(_), "异常", (x,y)=> Text.Contains(Text.From(x),y)) then "异常" else "正常", type text)

 

In addition, here is another approach which is close to your original idea. You should use List.Contains function instead. 

if List.Contains({[Device 1],[Device 2],[Device 3],[Device 4]}, "异常") then "异常" else "正常"

 

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

5 REPLIES 5
dufoq3
Super User
Super User

Hi @henryzf,,

 

Result

dufoq3_0-1720775694204.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKfrqn6emOHSmpSjpKiYlJSrE6YFEIPyk5KQUmogBRqABVmZgIkQDKAPkpEEmIGIQNFIUyYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    Ad_Custom = Table.AddColumn(Source, "Custom", each if List.Contains(Record.ToList(_), "异常", (x,y)=> Text.Contains(x,y)) then "异常" else "正常", type text)
in
    Ad_Custom

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi dufoq3, I still get error. see below. the 159 is from column ID. 
Expression.Error: We cannot convert the value 159 to type Text.
Details:
Value=159
Type=[Type]

henryzf_0-1721028777405.png

 

Anonymous
Not applicable

Hi @henryzf 

 

You only need to make a small modification to @dufoq3 's solution like below

= Table.AddColumn(#"Previous Step", "Custom", each if List.Contains(Record.ToList(_), "异常", (x,y)=> Text.Contains(Text.From(x),y)) then "异常" else "正常", type text)

 

In addition, here is another approach which is close to your original idea. You should use List.Contains function instead. 

if List.Contains({[Device 1],[Device 2],[Device 3],[Device 4]}, "异常") then "异常" else "正常"

 

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

finally I go with your List.Contains. it is worked. My original way is use List.ComtainsAny but it failed. Thanks so much for your help.

 

I don't see the full code and I don't see an error. Impossible to help here...

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