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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Super User
Super User

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
Super User
Super User

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
Employee
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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors