If and or DAX

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi

Please could you help me to build up a DAX formula with if, and, or:

If [a] = true
and or [c] = true
then = [d]

I wonder is it possible to sum up the total of and [c] rather than showing the result of [d]?
Many thanks.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Sorry for the typo, the question should be:

If [a] = "1"is true
and [e] ="2" or [c] = "3" is true
then to sum up the d value of [e] and [c]

Also, I would like to create a 'if and' formula with three criteria but it has syntax error, please could someone point out the mistake. Many thanks.


Actual Test = iferror(if(and([project]="A", [Unit]="B",[Name]="C"),[Actual]/[Budget],[Actual])),0)
 
Upvote 0
Hi,

AND operator in DAX accepts only two arguments, thus the syntax error. You might want to use "&&" instead:

Rich (BB code):
If([Project] = "A" && [Unit] = "B" && [Name] = "C")

The same goes for OR operator if you ever need to use it - it also accepts only two arguments so you need to replace it with "||".
 
Upvote 0
Thank you JustynaMK. Can I use the && in multiple ifs and I got confused with the right brackets and commas:

If([Project]="A" && [Unit]="B" && [Name] = "C"),[Actual]/100, if([Project]="D" && [Unit] = "E" && [Name] = "F"),[Actual]/200, [Actual])
 
Upvote 0
Yes, brackets can usually be a problem :) I suggest separating your code with "enter" - this one should work:

Rich (BB code):
If(
    [Project]="A" && [Unit]="B" && [Name] = "C",
    [Actual]/100, 
    If(
        [Project]="D" && [Unit] = "E" && [Name] = "F",
        [Actual]/200, 
        [Actual]
    )
)
 
Upvote 0
Please if I want to mix with && and ||, that is Project = A, or Project = B, and Unit = B, Name = C: is the code below correct please?

Rich (BB code):
If( [Project]="A" || [Project]="B" && [Unit]="B" && [Name] = "C", [Actual]/100, If( [Project]="D" && [Unit] = "E" && [Name] = "F", [Actual]/200, [Actual] ) )
 
Upvote 0

Forum statistics

Threads
1,213,527
Messages
6,114,140
Members
448,551
Latest member
Sienna de Souza

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top