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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

Power Query IF Condition

Hi Guys,

 

Can anyone help me with the below query, Like For the First 3 columns any of two columns contains "OK" then I need Will Fit All Product as "Y", If any one of the column contains -(Negative value) then I need to show it as "N".

 

Will Fit UNL

WIll Fit SUP

WILL Fit DSL

Will Fit All Product

ok

ok

ok

Y

ok

ok

-534(Values)

N

ok

Ok

- (Null/Blank)

Y

 

This is I need in Power Query editor

1 ACCEPTED SOLUTION
AntrikshSharma
Community Champion
Community Champion

@Anonymous Use this:

let
    Source = 
        Table.FromRows (
            Json.Document (
                Binary.Decompress (
                    Binary.FromText ( "i45Wys9W0oETsTrIArqmxiZoQkqxsQA=", BinaryEncoding.Base64 ),
                    Compression.Deflate
                )
            ),
            let
                _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
            in
                type table [ #"Will Fit UNL" = _t, #"WIll Fit SUP" = _t, #"WILL Fit DSL" = _t ]
        ),
    ChangedType = 
        Table.TransformColumnTypes (
            Source,
            {
                { "Will Fit UNL", type text },
                { "WIll Fit SUP", type text },
                { "WILL Fit DSL", type text }
            }
        ),
    Custom = 
        Table.AddColumn (
            ChangedType,
            "Will Fit All Product",
            each
                let
                    ValuesList = Record.ToList ( _ ),
                    OkCount = 
                        List.Count ( 
                            List.Select ( ValuesList, each _ = "ok" ) 
                        ) >= 2,
                    HasNegative = 
                        List.Count (
                            List.Select (
                                List.Transform ( 
                                    ValuesList, 
                                    each try Number.From ( _ ) otherwise null 
                                ),
                                each _ < 0
                            )
                        ) > 0,
                    Result = if OkCount and not HasNegative then "Y" else "N"
                in
                    Result,
                type text
        )
in
    Custom

View solution in original post

1 REPLY 1
AntrikshSharma
Community Champion
Community Champion

@Anonymous Use this:

let
    Source = 
        Table.FromRows (
            Json.Document (
                Binary.Decompress (
                    Binary.FromText ( "i45Wys9W0oETsTrIArqmxiZoQkqxsQA=", BinaryEncoding.Base64 ),
                    Compression.Deflate
                )
            ),
            let
                _t = ( ( type nullable text ) meta [ Serialized.Text = true ] )
            in
                type table [ #"Will Fit UNL" = _t, #"WIll Fit SUP" = _t, #"WILL Fit DSL" = _t ]
        ),
    ChangedType = 
        Table.TransformColumnTypes (
            Source,
            {
                { "Will Fit UNL", type text },
                { "WIll Fit SUP", type text },
                { "WILL Fit DSL", type text }
            }
        ),
    Custom = 
        Table.AddColumn (
            ChangedType,
            "Will Fit All Product",
            each
                let
                    ValuesList = Record.ToList ( _ ),
                    OkCount = 
                        List.Count ( 
                            List.Select ( ValuesList, each _ = "ok" ) 
                        ) >= 2,
                    HasNegative = 
                        List.Count (
                            List.Select (
                                List.Transform ( 
                                    ValuesList, 
                                    each try Number.From ( _ ) otherwise null 
                                ),
                                each _ < 0
                            )
                        ) > 0,
                    Result = if OkCount and not HasNegative then "Y" else "N"
                in
                    Result,
                type text
        )
in
    Custom

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.