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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
AllanBerces
Post Prodigy
Post Prodigy

PQ_Miltiple IF

Hi can anyone help me on my PQ, i want to use multiple if condition on my report. 

 

if Location is equal to South and Trade is equal to Mech then New Value is 21
if Location is equal to South and Trade is equal to Civil then New Value is 9
if Location is equal to South and Trade is equal to E&I then New Value is 6

if Location is equal to North, East and West and Trade is equal to Mech then New Value is 18
if Location is equal to North, East and West and Trade is equal to Civil then New Value is 10
if Location is equal to North, East and West and Trade is equal to E&I then New Value is 4

AllanBerces_0-1769051513672.png

DESIRED OUTPUT

AllanBerces_1-1769051545725.png

LocationTradeDateCurrentNew Value
SouthMech1/1/2026021
SouthCivil1/5/202609
SouthE&I1/19/202606
SouthMech2/2/2026021
SouthMech2/9/2026021
NorthE&I2/16/2026864
NorthMech3/2/202610118
NorthMech3/9/202611018
NorthE&I3/16/20261104
EastMech3/30/202611018
EastCivil4/6/202611010
EastE&I4/20/20261104
EastMech5/4/202613418
WestE&I5/11/20261344
WestMech5/25/202613418
WestMech6/1/202613418
WestE&I6/8/20261344
WestMech6/22/202611018
WestMech6/29/202611018
WestE&I7/6/20261204
3 ACCEPTED SOLUTIONS
cengizhanarslan
Super User
Super User

In Power Query → Add Column → Custom Column:

if [Location] = "South" and [Trade] = "Mech" then 21
else if [Location] = "South" and [Trade] = "Civil" then 9
else if [Location] = "South" and [Trade] = "E&I" then 6
else if List.Contains({"North","East","West"}, [Location]) and [Trade] = "Mech" then 18
else if List.Contains({"North","East","West"}, [Location]) and [Trade] = "Civil" then 10
else if List.Contains({"North","East","West"}, [Location]) and [Trade] = "E&I" then 4
else null

 

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

View solution in original post

BA_Pete
Super User
Super User

Hi @AllanBerces ,

 

In a new custom column ([New Value]) use the following code:

if [Location] = "South" and [Trade] = "Mech" then 21
else if [Location] = "South" and [Trade] = "Civil" then 9
else if [Location] = "South" and [Trade] = "E&I" then 6
else if List.Contains({"North", "East", "West"}, [Location]) and [Trade] = "Mech" then 18
else if List.Contains({"North", "East", "West"}, [Location]) and [Trade] = "Civil" then 10
else if List.Contains({"North", "East", "West"}, [Location]) and [Trade] = "E&I" then 4
else null   // This is your escape value if none of the conditions are met

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

vojtechsima
Super User
Super User

hey, @AllanBerces ,

if you want less repeated alternative code, check this:

    newColumns = 
        let 
            loc_s = "South",
            loc_new = {"North", "East", "West"},
            result = Table.AddColumn(previousStep, "New Value", each 
            let
                map =
                if [Location] = loc_s then [
                    Mech=21,
                    Civil=9,
                    #"E&I"=6
                ] 
                else if List.Contains(loc_new, [Location]) then [
                    Mech=18,
                    Civil=10,
                    #"E&I"=4
                ]
                else null
                in 
                Record.FieldOrDefault(map, [Trade], null)

            , Int64.Type
            )
            
    in
        result

 

 

the whole thingy with your input:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZGxCoMwEIbfxVm43CWmOheHDu3SoYN1KEWoUBBa7fM31hgvGrRDLgf5+D/4UxTRuenaRxRHx+reXwgIJEibVZhDGJXxBO3rT/38UQmnMg/Kr50wb4chLeOg9kCrJKAVpYOyAHRqXnMlAeqRTPuhPNLGycmJAvuZhjFnRRRLjHkl8w7sIM5v75YHShFMtNhYsIJZmBkMY15luG1vAspBUk3aSzXPSwDRRxUnXR4la4EW04B/ajWk21bTCQXbW2Dhb1tqd6xnsuWVXw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, Trade = _t, Date = _t, Current = _t, #"User New Value" = _t]),
    changeType = Table.TransformColumnTypes(Source,{{"Date", type date}}, "en-US"),
    previousStep = changeType,

    newColumns = 
        let 
            loc_s = "South",
            loc_new = {"North", "East", "West"},
            result = Table.AddColumn(previousStep, "New Value", each 
            let
                map =
                if [Location] = loc_s then [
                    Mech=21,
                    Civil=9,
                    #"E&I"=6
                ] 
                else if List.Contains(loc_new, [Location]) then [
                    Mech=18,
                    Civil=10,
                    #"E&I"=4
                ]
                else null
                in 
                Record.FieldOrDefault(map, [Trade], null)

            , Int64.Type
            )
            
    in
        result
in
    newColumns





Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

View solution in original post

7 REPLIES 7
vojtechsima
Super User
Super User

hey, @AllanBerces ,

if you want less repeated alternative code, check this:

    newColumns = 
        let 
            loc_s = "South",
            loc_new = {"North", "East", "West"},
            result = Table.AddColumn(previousStep, "New Value", each 
            let
                map =
                if [Location] = loc_s then [
                    Mech=21,
                    Civil=9,
                    #"E&I"=6
                ] 
                else if List.Contains(loc_new, [Location]) then [
                    Mech=18,
                    Civil=10,
                    #"E&I"=4
                ]
                else null
                in 
                Record.FieldOrDefault(map, [Trade], null)

            , Int64.Type
            )
            
    in
        result

 

 

the whole thingy with your input:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZGxCoMwEIbfxVm43CWmOheHDu3SoYN1KEWoUBBa7fM31hgvGrRDLgf5+D/4UxTRuenaRxRHx+reXwgIJEibVZhDGJXxBO3rT/38UQmnMg/Kr50wb4chLeOg9kCrJKAVpYOyAHRqXnMlAeqRTPuhPNLGycmJAvuZhjFnRRRLjHkl8w7sIM5v75YHShFMtNhYsIJZmBkMY15luG1vAspBUk3aSzXPSwDRRxUnXR4la4EW04B/ajWk21bTCQXbW2Dhb1tqd6xnsuWVXw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Location = _t, Trade = _t, Date = _t, Current = _t, #"User New Value" = _t]),
    changeType = Table.TransformColumnTypes(Source,{{"Date", type date}}, "en-US"),
    previousStep = changeType,

    newColumns = 
        let 
            loc_s = "South",
            loc_new = {"North", "East", "West"},
            result = Table.AddColumn(previousStep, "New Value", each 
            let
                map =
                if [Location] = loc_s then [
                    Mech=21,
                    Civil=9,
                    #"E&I"=6
                ] 
                else if List.Contains(loc_new, [Location]) then [
                    Mech=18,
                    Civil=10,
                    #"E&I"=4
                ]
                else null
                in 
                Record.FieldOrDefault(map, [Trade], null)

            , Int64.Type
            )
            
    in
        result
in
    newColumns





Any kudos or recognition appreciated. To learn more on the topic, check out my blog and follow me on LinkedIn.

Hi @vojtechsima @cengizhanarslan @BA_Pete thnak you you very much working as i need

BA_Pete
Super User
Super User

Hi @AllanBerces ,

 

In a new custom column ([New Value]) use the following code:

if [Location] = "South" and [Trade] = "Mech" then 21
else if [Location] = "South" and [Trade] = "Civil" then 9
else if [Location] = "South" and [Trade] = "E&I" then 6
else if List.Contains({"North", "East", "West"}, [Location]) and [Trade] = "Mech" then 18
else if List.Contains({"North", "East", "West"}, [Location]) and [Trade] = "Civil" then 10
else if List.Contains({"North", "East", "West"}, [Location]) and [Trade] = "E&I" then 4
else null   // This is your escape value if none of the conditions are met

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




cengizhanarslan
Super User
Super User

In Power Query → Add Column → Custom Column:

if [Location] = "South" and [Trade] = "Mech" then 21
else if [Location] = "South" and [Trade] = "Civil" then 9
else if [Location] = "South" and [Trade] = "E&I" then 6
else if List.Contains({"North","East","West"}, [Location]) and [Trade] = "Mech" then 18
else if List.Contains({"North","East","West"}, [Location]) and [Trade] = "Civil" then 10
else if List.Contains({"North","East","West"}, [Location]) and [Trade] = "E&I" then 4
else null

 

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

Hi @BA_Pete @cengizhanarslan thank you for the reply but ir show error

 

AllanBerces_0-1769072064153.png

 

You should add this to your current m expression in a correct way. If you share your whole code I can share you the corrected query.

_________________________________________________________
If this helped, ✓ Mark as Solution | Kudos appreciated
Connect on LinkedIn
AI-assisted tools are used solely for wording support. All conclusions are independently reviewed.

Hi @cengizhanarslan @BA_Pete thnak you for the reply but when i try this part all are ok

if [Location] = "South" and [Trade] = "Mech" then 21
else if [Location] = "South" and [Trade] = "Civil" then 9
else if [Location] = "South" and [Trade] = "E&I" then 6

but when i try this part show error

AllanBerces_0-1769072841721.png

Thank you

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

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.