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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
jcastr02
Post Prodigy
Post Prodigy

Custom column based on whats contained in a row

I was trying to create a custom column in power query (a yes/no column is fine)   that if any of the values in the row contains *00:00, the FE Yes/No column would be "No, if not then "Yes"  see below data example and desired result in last column

Location numberFE Sun OpenFE Sun CloseFE Mon OpenFE Mon CloseFE Tue OpenFE Tue CloseFE Wed OpenFE Wed CloseFE Thu OpenFE Thu CloseFE Fri OpenFE Fri CloseFE Sat OpenFE Sat CloseFE Yes/No
2692*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
2761*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
3145*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
31818:0022:007:0022:007:0022:007:0022:007:0022:007:0022:008:0022:00Yes
3400*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
3446*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
36899:0021:007:0021:007:0021:007:0021:007:0021:007:0021:007:0021:00Yes
4212*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
4549*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
4768*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
5192*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
6072*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
6191*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00*00:00No
6564*08:00*22:00*08:00*22:00*08:00*22:00*08:00*22:00*08:00*22:00*08:00*22:00*08:00*22:00Yes
68317:0024:00:007:0024:00:007:0024:00:007:0024:00:007:0024:00:007:0024:00:007:0024:00:00Yes
2 ACCEPTED SOLUTIONS

Hi @jcastr02 ,

 

Please try:

= Table.AddColumn(#"Changed Type", "Custom", each if List.ContainsAny({Record.Field(_, "FE Sat Open"), Record.Field(_, "FE Sat Close")}, {"*00:00"}) then "Yes" else "No")

 

Best Regards,

Bof

View solution in original post

Create a new step by clicking FX button and then paste that code in Editor, what you're doing is pasting the code in a custom column.

View solution in original post

7 REPLIES 7
v-bofeng-msft
Community Support
Community Support

Hi @jcastr02 ,

 

I've made a test for yor reference:

 

if List.ContainsAny(Record.FieldValues(_), {"*00:00"}) then "Yes" else "No"

 

vbofengmsft_0-1731378184922.png

Best Regards,

Bof

Apologies, I should have clarified - what if I Only wanted to check within this table for specific columns, such as FE Sat Open and FE Sat Close (as example) - how could I tailor to list out the specific columns?

Hi @jcastr02 ,

 

Please try:

= Table.AddColumn(#"Changed Type", "Custom", each if List.ContainsAny({Record.Field(_, "FE Sat Open"), Record.Field(_, "FE Sat Close")}, {"*00:00"}) then "Yes" else "No")

 

Best Regards,

Bof

Hello @v-bofeng-msft Thanks so much.  I tried to enter this , however getting different answers when the values are the same in the rows.  Any ideas?  Thanks so much.

 

formula.pngCustom Column.png

Create a new step by clicking FX button and then paste that code in Editor, what you're doing is pasting the code in a custom column.

Omid_Motamedise
Memorable Member
Memorable Member

Just copy and past the following code into the Advance editor.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zZSxDoMwDET/JSNisI1zsfmI7hVi7Nyh/y+VEiK1ZUXgKfENyctFd9OUBC6pTx3RSHTV5vZMc7+wFHAUloE1x2Gxjy9WRZG6luPGv5Pvj1e9V697+s4DVYRhgfky+eYa/3p6/Nj+Q4XDZFWzehiWAovCkjlOn4JKHBb2MN2ODF3lrfe6VnxnKi3UsIG/Iq9jgz1TWWHmNw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Location number" = _t, #"FE Sun Open" = _t, #"FE Sun Close" = _t, #"FE Mon Open" = _t, #"FE Mon Close" = _t, #"FE Tue Open" = _t, #"FE Tue Close" = _t, #"FE Wed Open" = _t, #"FE Wed Close" = _t, #"FE Thu Open" = _t, #"FE Thu Close" = _t, #"FE Fri Open" = _t, #"FE Fri Close" = _t, #"FE Sat Open" = _t, #"FE Sat Close" = _t, #"FE Yes/No" = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Yes/No", each if Text.Contains(Text.Combine(List.Transform(Record.ToList(_),Text.From),"|"),"*00:00") then "No" else "Yes")
in
    #"Added Custom"

 

If this answer helped resolve your issue, please consider marking it as the accepted answer. And if you found my response helpful, I'd appreciate it if you could give me kudos. 

Thank you!

Apologies, I should have clarified - what if I Only wanted to check within this table for specific columns, such as FE Sat Open and FE Sat Close (as example) - how could I tailor to list out the specific columns?

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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