Forum Discussion

KWelsh8144's avatar
KWelsh8144
Helper II
3 years ago
Solved

IF statement with multiple conditions for unique IDs

I'm trying to get an if statement that looks at each unique ID and then meets the following criteria: 

 

Each ID must have Complete = yes, and Type = 20 OR Type = 13 AND 23

 

The flag column would be the expected result.

 

IDTypeCompleteFlag
12320Yes1
1234Yes1
45620No0
45618Yes0
4565Yes0
78923Yes1
78913Yes1
7896Yes1

I tried something like this: 

*Flag = if(
and(
or(
and(Table[Type] = 23, Table[Type] = 13),
Table[Type] = 20),
Table[Complete]="Yes"),
1, 0) 

 

But this doesn't seem to work since each ID has multiple rows. Any ideas? 

  • Hi,

    Try this calculated column formula instead

    Column1 = 1*(or(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&(Data[Type]=20))),and(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&Data[Type]=23)),CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&Data[Type]=13)))))

    Hope this helps.

9 Replies

  • Hi,

    Write this calculated column formula

    Column = if(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&(Data[Type]=20)||Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&(Data[Type]=23||Data[Type]=13)))>=1,1,0)

    Hope this helps.

    • KWelsh8144's avatar
      KWelsh8144
      Helper II

      Thanks for the response - but this isn't working for me either.  If someone has a 13 or 23, it's flagging that as a 1, when they need to have both 13 and 23 , or just a 20 in the type. Any ideas?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        Try this calculated column formula instead

        Column1 = 1*(or(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&(Data[Type]=20))),and(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&Data[Type]=23)),CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[Complete]="Yes"&&Data[Type]=13)))))

        Hope this helps.