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
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors