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
Applicable88
Impactful Individual
Impactful Individual

Flag with Yes or No Based on two columns string, which is not on the same row

Hello,

 

I need a Column Flag base on two other columns, telling me if there is a condition met. My sample table:

DepartmentGuardsHelpers
Security  
Securitysufficient 
Security not sufficient
Security  
Warehousesufficient 
Warehouse sufficient
Subsidiary  
Subsidiarynot sufficient
Subsidiary  
Subsidiary sufficient
Subsidiary  
Subsidiary  

 

First column is the department. If the columns "guards" and "helpers" got sufficient then a fourth column should say "YES". My problem is that sufficient and not sufficient created from the database are not on the same row. So the row context with if - statement failed.

 

The Flag I'm looking for a calculated column:

DepartmentGuardsHelpersFlag
Security  No
Securitysufficient No
Security not sufficientNo
Security  No
Warehousesufficient Yes 
Warehouse sufficientYes 
Subsidiary  No
Subsidiarynot sufficientNo
Subsidiary  No
Subsidiary sufficientNo
Subsidiary  No
Subsidiary  No

Hope someone has an idea.

Thank you very much in advance.

Best reagards. 

2 ACCEPTED SOLUTIONS

Please try:

Column = 
var guards_ = CALCULATE(DISTINCTCOUNT('Table'[Department]),FILTER('Table',EARLIER('Table'[Department])='Table'[Department]&&'Table'[Guards]="sufficient"))
var helpers = CALCULATE(DISTINCTCOUNT('Table'[Department]),FILTER('Table',EARLIER('Table'[Department])='Table'[Department]&&'Table'[Helpers]="sufficient"))
var count_ = guards_+helpers
return IF(count_=2,"Yes","No"
)

Vlianlmsft_0-1627023406226.png

 

View solution in original post

EARLIER function was a way to manipulate the context of a calculation within a particular formula.

The EARLIER function allows us to jump from one context to a prior row context.

In this formula, the EARLIER function is used as the condition of distinctcount of other guards... from the same Department against each guards... .

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Applicable88 , Create a new column like

 

new column =
var _cnt_ns = countx(filter(Table, [Department] = earlier([Department]) && [Guards] = "not sufficient" || [Helpers] = "not sufficient"), [Department])
var _cnt_s = countx(filter(Table, [Department] = earlier([Department]) && [Guards] = "not sufficient" || [Helpers] = "sufficient"), [Department])
return
if(not(isblank(_cnt_s)) && isblank(_cnt_ns) , "Yes", "No")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak , it shows me "No" for every case, even the "Warehouse" department meet the criteria.

 

Please try:

Column = 
var guards_ = CALCULATE(DISTINCTCOUNT('Table'[Department]),FILTER('Table',EARLIER('Table'[Department])='Table'[Department]&&'Table'[Guards]="sufficient"))
var helpers = CALCULATE(DISTINCTCOUNT('Table'[Department]),FILTER('Table',EARLIER('Table'[Department])='Table'[Department]&&'Table'[Helpers]="sufficient"))
var count_ = guards_+helpers
return IF(count_=2,"Yes","No"
)

Vlianlmsft_0-1627023406226.png

 

@V-lianl-msft wow... I think thats it. Can you explain to me whats happening in the Filter part of your function? I read about the earlier() function, but I don't understand what it is actually doing. 

And will this formula also works when "sufficient" of Helpers always comes first and the "sufficient" of Guards comes rows below it? Does the earlier function has an impact on this? And also why there is a ealier function but not like an "later()" function availabe. For examle SQL has lead and lag. 

Thank you very much. 

Best. 

EARLIER function was a way to manipulate the context of a calculation within a particular formula.

The EARLIER function allows us to jump from one context to a prior row context.

In this formula, the EARLIER function is used as the condition of distinctcount of other guards... from the same Department against each guards... .

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
Top Kudoed Authors