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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
KWelsh8144
Helper II
Helper II

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? 

1 ACCEPTED SOLUTION

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

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.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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?

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

THank you!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
FreemanZ
Super User
Super User

hi @KWelsh8144 

can you also provide the expected column?

@FreemanZ sure! i updated the original post. thanks!

hi @KWelsh8144 

could you explain how comes 1 for 4 and 6?

FreemanZ_0-1676679106158.png

 

I don't necessary need it that way if it could only show for the conditions that it meets - that's fine as well, but what i was getting at was that, that particular unique ID meets the criteria of the if statement. However, if it would instead only show a 1 for records with a 20 OR 23 and 13, that would work too.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.