Forum Discussion

bbdiver526's avatar
bbdiver526
Frequent Visitor
8 years ago
Solved

IF formula with multiple conditions

I'm relatively new to PowerBI and DAX statements and I'm having an issue with writing an IF statement with multiple conditions.

 

I need to use the Volume if it is current year, type is Actuals and company is ITA.

 

These are the DAX statements I have tried:

_CurrentYearITA = IF(AND('AMER DBP Retail Bookings'[DTF_Current_ITA_YTD] = "Y",'AMER DBP Retail Bookings'[PL_PlanCode] = "ACTUALS",'AMER DBP Retail Bookings'[CO_Company] = "ITA"),'AMER DBP Retail Bookings'[_Volume],0)

This statement says too many arguments for the AND function

 

and

 

_CurrentYearITA = IF('AMER DBP Retail Bookings'[DTF_Current_ITA_YTD] = "Y"||'AMER DBP Retail Bookings'[PL_PlanCode] = "ACTUALS"||'AMER DBP Retail Bookings'[CO_Company] = "ITA";'AMER DBP Retail Bookings'[_Volume];0)

This statement says incorrect syntax starting at the semi-colon after "ITA"

6 Replies

  • anandav's avatar
    anandav
    Skilled Sharer

    bbdiver526,

    AND function can take only 2 parameters.

    Check the documentation.

     

    You will need to chain the AND operator && to achieve what you want.

    e.g.

     

    • bbdiver526's avatar
      bbdiver526
      Frequent Visitor

      anandav,

      Thanks for the info. It seems to be working now. I'm not familiar with DAX syntax having just started using it and your response was helpful. I appreciate it.

      • dexterz's avatar
        dexterz
        Helper II
        SWITCH (
            TRUE (),
            Product[Size] = "XL" && Product[Color] = "Red", "Red and XL",
            Product[Size] = "XL" && Product[Color] = "Blue", "Blue and XL",
            Product[Size] = "L" && Product[Color] = "Green", "Green and L"
        )
  • Anonymous's avatar
    Anonymous
    Not applicable

    The AND function only lets you compare 2 things.  However you can nest further AND statements.  This can be something like 

    _CurrentYearITA = IF(
    	AND(
    		'AMER DBP Retail Bookings'[DTF_Current_ITA_YTD] = "Y",
    		AND(
    			'AMER DBP Retail Bookings'[PL_PlanCode] = "ACTUALS",
    			'AMER DBP Retail Bookings'[CO_Company] = "ITA"
    		)
    	),
    	'AMER DBP Retail Bookings'[_Volume],
    	0
    )

     

    From a best practice perspective, the SWITCH statement is the way to go.