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
Anonymous
Not applicable

if Function in Custom Column returns inconsistent result - what am I doing wrong ?

Hello everyone, I'm new to Power BI and having trouble with what should be a fairly simple if statement, so would really appreciate some help.

 

I need to create 2 new columns Admin and Meetings to split out the General Minutes data based on this criteria:

General, where TaskId is blank and Type = 14.   

Meetings where TaskId is blank and Type is either 1, 2 or 8.

 

I got this far:

= Table.AddColumn(#"Added Conditional Column2", "General", each if [TaskId] = null and [Type] = 14 then [Minutes] else "")

This doesn't return anything.

 

= Table.AddColumn(#"Added Custom", "Meetings", each if [TaskId] = null and [Type] = 1 or [Type] = 2 or [Type] = 8 then [Minutes] else "")

This strangely returns [Minutes] for types 2 and 8 but not 1, so I'm confused.

 

TaskIdMinutesTypeTask MinutesGeneral MinutesAdminMeetings
23437830430   
234378241224   
252970656   
252503636   
23437818013180   
23437830330   
NULL6014 60  
NULL901 90  
NULL6014 60  
NULL4508 450 450
NULL4508 450 450
NULL902 90 90
NULL4808 480 480
NULL4808 480 480

 

Any help would be very welcome, thanks

Andy

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Anonymous 

Based on the sample data you have offered,  you need to make sure that:

The data type of the taskid is whole number,  and the minutes type should also be whole number, it should be like the following piture

vxinruzhumsft_1-1717465114615.png

 

Then you can try the following code in custom column.

General:

 

if [TaskId]=null and [Type] = 14 then [Minutes] else null

 

Meetings:

 

if [TaskId] = null and ([Type] = 1 or [Type] = 2 or [Type] =8 ) then [Minutes] else null

 

Output

vxinruzhumsft_2-1717465132700.png

And you can refer to the following code in Advanced Editor in power query.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jY5REgARCIavsuPZAxVyFuP+11i17DA8eCjl+/+qFANImNhYg64lGsWjUe0kAIEeRjUpAuQkptgi9HfBwWH/xh2P+Z5lhse/PGj0NtyPlKnqHpdFN7OsrKPsbm0UpOXOvu4O6g44LiRefHwD6ws=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TaskId = _t, Minutes = _t, Type = _t, #"Task Minutes" = _t, #"General Minutes" = _t, Admin = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"TaskId", Int64.Type}, {"Minutes", Int64.Type}, {"Type", Int64.Type}, {"Task Minutes", Int64.Type}, {"General Minutes", Int64.Type}, {"Admin", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "General", each if [TaskId]=null and [Type] = 14 then [Minutes] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Meetings", each if [TaskId] = null and ([Type] = 1 or [Type] = 2 or [Type] =  then [Minutes] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Admin"})
in
    #"Removed Columns"

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Great, that works fine, thank you for your help Yolo !

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous 

Based on the sample data you have offered,  you need to make sure that:

The data type of the taskid is whole number,  and the minutes type should also be whole number, it should be like the following piture

vxinruzhumsft_1-1717465114615.png

 

Then you can try the following code in custom column.

General:

 

if [TaskId]=null and [Type] = 14 then [Minutes] else null

 

Meetings:

 

if [TaskId] = null and ([Type] = 1 or [Type] = 2 or [Type] =8 ) then [Minutes] else null

 

Output

vxinruzhumsft_2-1717465132700.png

And you can refer to the following code in Advanced Editor in power query.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jY5REgARCIavsuPZAxVyFuP+11i17DA8eCjl+/+qFANImNhYg64lGsWjUe0kAIEeRjUpAuQkptgi9HfBwWH/xh2P+Z5lhse/PGj0NtyPlKnqHpdFN7OsrKPsbm0UpOXOvu4O6g44LiRefHwD6ws=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TaskId = _t, Minutes = _t, Type = _t, #"Task Minutes" = _t, #"General Minutes" = _t, Admin = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"TaskId", Int64.Type}, {"Minutes", Int64.Type}, {"Type", Int64.Type}, {"Task Minutes", Int64.Type}, {"General Minutes", Int64.Type}, {"Admin", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "General", each if [TaskId]=null and [Type] = 14 then [Minutes] else null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Meetings", each if [TaskId] = null and ([Type] = 1 or [Type] = 2 or [Type] =  then [Minutes] else null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Admin"})
in
    #"Removed Columns"

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Great, that works fine, thank you for your help Yolo !

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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