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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Shan_Drex12
Helper I
Helper I

If not custom column

Hi All,

 

I'm looking to calculating a custom column in power query using a if statement.

 

I have this column 1 ( scac) that IF it equals to the specific codes below it would mutiple Column 2 (# of days) by $250.

 

Column 1 (scac)Column 2 (# of days)
MONO

5

SHEK10
VTEC12

 

IF not then multiply column 2 (# of days) by $35.

 

I have this formula, below but it seems to not to be working, 

If [SCAC] = "MONU" or [SCAC] = "SHEK" or [SCAC] = "VTEC" then [# "of Days in Detention"] * 250 else [# "of Days in Detention"] * 35

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Shan_Drex12 

 

the formula has to be like this

if [#"Column 1 (scac)"]="MONO" or [#"Column 1 (scac)"]="SHEK" or [#"Column 1 (scac)"]="VTEC" then [#"Column 2 (# of days)"]*250 else [#"Column 2 (# of days)"]*35

here the complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8vX381fSUTJVitWJVgr2cPUGcgwNwLywEFdnEM9IKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column 1 (scac)" = _t, #"Column 2 (# of days)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column 1 (scac)", type text}, {"Column 2 (# of days)", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [#"Column 1 (scac)"]="MONO" or [#"Column 1 (scac)"]="SHEK" or [#"Column 1 (scac)"]="VTEC" then [#"Column 2 (# of days)"]*250 else [#"Column 2 (# of days)"]*35)
in
    #"Added Custom"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

1 REPLY 1
Jimmy801
Community Champion
Community Champion

Hello @Shan_Drex12 

 

the formula has to be like this

if [#"Column 1 (scac)"]="MONO" or [#"Column 1 (scac)"]="SHEK" or [#"Column 1 (scac)"]="VTEC" then [#"Column 2 (# of days)"]*250 else [#"Column 2 (# of days)"]*35

here the complete example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8vX381fSUTJVitWJVgr2cPUGcgwNwLywEFdnEM9IKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column 1 (scac)" = _t, #"Column 2 (# of days)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column 1 (scac)", type text}, {"Column 2 (# of days)", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [#"Column 1 (scac)"]="MONO" or [#"Column 1 (scac)"]="SHEK" or [#"Column 1 (scac)"]="VTEC" then [#"Column 2 (# of days)"]*250 else [#"Column 2 (# of days)"]*35)
in
    #"Added Custom"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors