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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
markabdey
Frequent Visitor

Where Clause for Custom Column

Hi

In Power Query I'm trying to create a Custom Column that is populated by a value from another column in the same table where a flag is set to 'Y'. I can't seem to get the right syntax in M to get it to work. Can anyone help please? Example below. Thanks.

 

Time        Flag     Custom Column

07:30       N         07:45

07:45       Y          07:45

08:00       N         07:45

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @markabdey 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjC3MjY4tEBJR8lPKVYHzDcxBfMjIXwLKwO4fCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Flag = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}, {"Flag", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each #"Changed Type"{[Flag="Y"]}[Time], type time)
in
    #"Added Custom"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

4 REPLIES 4
AlB
Community Champion
Community Champion

Hi @markabdey 

Place the following M code in a blank query to see the steps.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjC3MjY4tEBJR8lPKVYHzDcxBfMjIXwLKwO4fCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Time = _t, Flag = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}, {"Flag", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each #"Changed Type"{[Flag="Y"]}[Time], type time)
in
    #"Added Custom"

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

mahoneypat
Microsoft Employee
Microsoft Employee

This would be easier with DAX but it can be done in the query editor too.  Will all rows have the same value in that column (as with your example), or are there other columns and the Y value within a group needs to be found?  If the latter, please update your example data to reflect that so you get what you need.

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks for your reply. The value will be the same across all the rows.

Fowmy
Super User
Super User

@markabdey 

Click the Custom column and enter the following code:

=if [Flag] = "Y" then [Time] else null

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.