cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
EricWu
Frequent Visitor

Need help on calculated column

Project CodeFlag
1A1
1B1
1C1
2B1
2C1
3D0
3F0
3Q0
4B1
5A0
6C0

 

I want to create a caculated column Flag, If project contains Code B then all records in project will be flgged as 1.  By the way, If the requirment is measure,how to create?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@EricWu Maybe:

 

Column = 
  VAR __Project = [Project]
  VAR __Codes = DISTINCT(SELECTCOLUMNS(FILTER('Table',[Project]=__Project),"Code",[Code]))
RETURN
  IF("B" IN __Codes,1,0)

Measure =
  VAR __Project = MAX([Project])
  VAR __Codes = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[Project]=__Project),"Code",[Code]))
RETURN
  IF("B" IN __Codes,1,0)

 

 


@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This calculated column works as well

=if(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[Project]=EARLIER(Data[Project])&&Data[Code]="B"))>0,1,0)

Hope this helps.

Untitled.png


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

@EricWu Maybe:

 

Column = 
  VAR __Project = [Project]
  VAR __Codes = DISTINCT(SELECTCOLUMNS(FILTER('Table',[Project]=__Project),"Code",[Code]))
RETURN
  IF("B" IN __Codes,1,0)

Measure =
  VAR __Project = MAX([Project])
  VAR __Codes = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[Project]=__Project),"Code",[Code]))
RETURN
  IF("B" IN __Codes,1,0)

 

 


@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop! Microsoft Hates Greg's Quick Measures
YouTube Channel! Microsoft Hates Greg
Check out my latest book!

View solution in original post

@Greg_Deckler  Thanks a lot, it worked perfertly

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.