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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

For Each and Exists clause implementation in DAX

Hi,

 

Im trying to implement a complex logic that looks easy on algorith but tough when comes to implemenation.

Any help on M code or DAX side should be helpful

 

Algorithm:

 

 

 

 

if Executed Flag = 1 then
		(Only)if Title Flag 202 and 203 both exist for each Feature ID then
				(Only if User Story Status of both 202 and 203 Title Flags = "Complete or Closed" then
						"Workshop Completed"
	
						else "Workshop Executed but not completed" 
						// happens when Title Flags 202 or 203 either 
						//one exists or none exists for each Feature ID. 
						//Or any one or both of these 2 user story status = "Pending"
		else "Workshop Executed but not completed"
else if Execute Flag = 0 then "Not Executed"
//Note that workshop Status is at feature level and hence it can't be differnt for same feature id

 

 

 

 

 

Table

 

I have color coded different features with different colors for understanding the last column(output).

Feature IDUser Story IDUser Story StatusTitle FlagExecuted FlagWorkshop Status(Output Column)
RFID001USIDR4Pending 1Workshop Complete
RFID001USIDR5Complete or Closed2021Workshop Complete
RFID001USIDR6Complete or Closed2031Workshop Complete
RFID002USIDR7Complete or Closed 1Workshop Not Complete
RFID002USIDR8Pending 1Workshop Not Complete
RFID002USIDR9Complete or Closed2021Workshop Not Complete
RFID002USIDR10Pending2030Workshop Not Complete
RFID003USIDR11Complete or Closed2031Workshop Executed but not completed
RFID004USIDR12Complete or Closed2030Not Executed
RFID005USIDR13Complete or Closed2020Not Executed
6 REPLIES 6
PhilipTreacy
Super User
Super User

@Anonymous 

Let me know if this issue is fixed with the file I modified for you to fix the text/integer comparison problem.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@tex628 did exactly what you did, with some minor corrections

Here is the DAX

Calculated Column =
VAR id1 = [Feature ID]
RETURN
IF (
[Executed Flag] = 1,
IF (
CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Feature ID] = id1,
OR ( 'Table'[Feature ID] = "203", 'Table'[Title Flag] = "203" ) = 2
),
IF (
CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Feature ID] = id1,
'Table'[User Story Status] = "Complete or Closed"
) = 2,
"Workshop Complete",
"Workshop Executed but not Completed"
),
"Workshop Executed but not Completed"
),
"Not Executed"
)
 
and here is the error
 
 
 

The expression contains multiple columns, but only a single column can be usedn a True False expressions that is used as atable filter calculation

 

 

 

tex628
Community Champion
Community Champion

Revised it a little bit. 

Give this a try:

 

Calculated Column = 
VAR id1 = [Feature ID]
RETURN
IF (
[Executed Flag] = 1,
IF (
CALCULATE (
COUNTROWS ( 'Table' ),
ALL('Table'),
'Table'[Feature ID] = id1,
'Table'[Title Flag] IN {"202" , "203"}
) = 2,
IF (
CALCULATE (
COUNTROWS ( 'Table' ),
ALL('Table'),
'Table'[Feature ID] = id1,
'Table'[Title Flag] IN {"202" , "203"},
'Table'[User Story Status] = "Complete or Closed"
) = 2,
"Workshop Complete",
"Workshop Not Complete"),
"Workshop Executed but not Completed"),
IF(
    'Table'[User Story Status] = "Pending" && 
    CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Title Flag] IN {"202" , "203"}
) > 0 ,
"Workshop Not Complete" ,
"Not Executed")
)

 


Connect on LinkedIn
Anonymous
Not applicable

@PhilipTreacy can you please help me with the logic

Anonymous
Not applicable

@PhilipTreacy I just want to make sure that

calculated column that I have created and the workshop status(output) match exactly.

tex628
Community Champion
Community Champion

Give this DAX column a try and let me know how it goes! 

Calculated Column = 
var id = [Feature ID]
Return
IF ( [Executed Flag] = 1 ,
IF ( CALCULATE( COUNTROWS( 'Table' ) , [Feature ID] = id, OR( [Title Flag] = 203 , [Title Flag] = 203] )) = 2 , 
IF ( CALCULATE( COUNTROWS( 'Table' ) , [Feature ID] = id, [User Story] = "Complete or Closed" ) = 2 , 
"Workshop Complete" , 
"Workshop Not Complete" , 
"Workshop Executed but not completed", 
"Not Executed" 
))) 

Connect on LinkedIn

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors