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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

variable + if stament

hello i'm trying to translate this python code into dax using variable 

def force(p😞
    if p["Zones_A"] == "4" and p["Zone_C"] == "4":
        return p["net"]
    elif p["Zones_A"] == "4" and p["Zone_C"] == "3":
        return p["CA_fid_CRF"]*mvt["Effet"][mvt["Mvt"]=="B-C"]
    elif p["Zones_futures"] == "4" and p["Zone_future_ap_reco"] == "2":
        return p["CA_fid_CRF"]*mvt["Effet"][mvt["Mvt"]=="B-D"]
    elif p["Zones_futures"] == "4" and p["Zone_future_ap_reco"] == "1":
        return p["CA_fid_CRF"]*mvt["Effet"][mvt["Mvt"]=="B-E"]
    elif p["Zones_futures"] == "4" and p["Zone_future_ap_reco"] == "0":
        return p["CA_fid_CRF"]*mvt["Effet"][mvt["Mvt"]=="B-NA"]
    elif p["Zones_futures"] == "3" and p["Zone_future_ap_reco"] == "4":
        return p["CA_fid_CRF"]*mvt["Effet"][mvt["Mvt"]=="C-B"]
    elif p["Zones_futures"] == "3" and p["Zone_future_ap_reco"] == "3":
        return p["gain_net"]

and what i'm trying to do with dax


calcule_intensité =
var A = result[Zones_actuelles]
var B = result[Zones_futures]
var C = result[Zone_future_ap_reco]
var d = result[CA_fid_CRF]
var g = result[gain_net]
var Effet = result[Mvt_Force]

return
SWITCH(
IF( B= 4 && C=4,g,
IF(B = 4 && C = 3,CALCULATE(SUM(d)*SUM(result[Mvt_Force]=))))
but actually i'm lost, can someone help me please 🙂
 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You need to try Switch(True(),

example

SWITCH(true(),
search("Red",[column1],1,0)>0 || search("Green",[column1],1,0)>0 ,"C1"
search("Yellow",[column1],1,0)<0 , "C1",
blank()
)

 

Also, it can only one data type. so take care of that

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , You need to try Switch(True(),

example

SWITCH(true(),
search("Red",[column1],1,0)>0 || search("Green",[column1],1,0)>0 ,"C1"
search("Yellow",[column1],1,0)<0 , "C1",
blank()
)

 

Also, it can only one data type. so take care of that

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
mahoneypat
Microsoft Employee
Microsoft Employee

Please see this post on SWITCH(TRUE(), ... which would be best approach for your scenario.

 

https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

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


Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors