If and or DAX

Apple08

Active Member
Joined
Nov 1, 2014
Messages
348
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.
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Apple08

Active Member
Joined
Nov 1, 2014
Messages
348
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)
 

JustynaMK

Well-known Member
Joined
Aug 28, 2016
Messages
647
Office Version
365, 2013
Platform
Windows
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 "||".
 

Apple08

Active Member
Joined
Nov 1, 2014
Messages
348
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])
 

JustynaMK

Well-known Member
Joined
Aug 28, 2016
Messages
647
Office Version
365, 2013
Platform
Windows
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]
    )
)
 

Apple08

Active Member
Joined
Nov 1, 2014
Messages
348
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] ) )
 

Watch MrExcel Video

Forum statistics

Threads
1,102,351
Messages
5,486,357
Members
407,541
Latest member
Emilybuhman

This Week's Hot Topics

Top