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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
powerbi_bi
Frequent Visitor

Create a FLAG column with 1 or 0

Hi,

I have a table

IDCASE_IDCOUNTRY
1AAAUSA
1AAAJAPAN
1AAACHINA
2BBBCHINA
2BBBCHINA
2BBBCHINA
2BBBCHINA
3CCCUSA
3CCCJAPAN

 

I want to create a FLAG (Calculated_Column) with 1 or 0 based on the conditions

 

IDCASE_IDCOUNTRYCALCULATED_COLUMN
1AAAUSA1
1AAAJAPAN1
1AAACHINA1
2BBBCHINA0
2BBBCHINA0
2BBBCHINA0
2BBBCHINA0
3CCCUSA1
3CCCJAPAN1

 

The condition is:

If one CASE_ID has more than one country assigned then its 1 else 0

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@powerbi_bi This should work Smiley Happy

 

Flag Column =
IF (
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[COUNTRY] ),
        ALLEXCEPT ( 'Table', 'Table'[CASE_ID] )
    )
        = 1,
    0,
    1
)

2010-10-04 - Conditional Column.png

 

View solution in original post

3 REPLIES 3
Sean
Community Champion
Community Champion

@powerbi_bi This should work Smiley Happy

 

Flag Column =
IF (
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[COUNTRY] ),
        ALLEXCEPT ( 'Table', 'Table'[CASE_ID] )
    )
        = 1,
    0,
    1
)

2010-10-04 - Conditional Column.png

 

I have a similar question based on the same data. How does the calculation change if I want my flag column to indicate whether a case has a CHINA value? Do I need a filter value in the DISTINCTCOUNT function?

 

My use case is that I want to see all countries for cases that have a CHINA value. Thanks!

Thanks Sean for the quick reply
Works Great!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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