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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
hana123
Frequent Visitor

The power bi does not calculate identities in different rows

hi everyone 

 

this is the my table 

 

 

ID    isDiagnosisDiabetes          isDiagnosisHeartFailure       isDiagnosisHypertension             Date 

1                 Yes                                      No                                          No                                 1/1/2022

1                  No                                      No                                          Yes                                2/7/2022

 

 

i would like to Count any patient with more than one diseases

but power bi in this case will return 0 id 

when should return 1 

becuse patient number 1 has Diabetes and hypertension (more than one diseases ) but becuse it happend in different dates (rows)

power bi will not count it ! 

 

 

how can i Solve this problem? 

 

THANK YOU 

2 ACCEPTED SOLUTIONS
AlB
Community Champion
Community Champion

Hi @hana123 

See it all at work in the attached file.

Best to unpivot the columns to get a more manageable table structure first. 

Then you can create a measure for the number of patients:

MoreThan1DiseaseFlag = 
VAR aux_ =
    CALCULATE ( DISTINCTCOUNT ( Table1[Diagnosis] ), Table1[Result] = "Yes" ) > 1
RETURN
    IF ( aux_, 1, 0 )

 that uses this other measure:

NumPatientsWithMoreThan1Disease = 
SUMX ( DISTINCT ( Table1[ID] ), [MoreThan1DiseaseFlag] )

You can also use [MoreThan1DiseaseFlag] to show in a table visual the list of patients with more than one disease, by using the measure as a table visual and selecting it to show when the value is 1

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

FreemanZ
Super User
Super User

hi @hana123 

you may create a measure like this:

PatientsWithMultiDisease = 
SUMX(
    VALUES(data[ID]),
    VAR _db =
    CALCULATE(COUNTROWS(data), data[IsDB]="Yes")
    VAR _hf =
    CALCULATE(COUNTROWS(data), data[IsHF]="Yes")
    VAR _ht =
    CALCULATE(COUNTROWS(data), data[IsHT]="Yes")
    RETURN
    IF(_db+_hf+_ht>1, 1, 0)
)

 

i tried to expand your data sample:

FreemanZ_0-1672749889588.png

and verified the measure with a card visual:

FreemanZ_1-1672749959712.png

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @hana123 

you may create a measure like this:

PatientsWithMultiDisease = 
SUMX(
    VALUES(data[ID]),
    VAR _db =
    CALCULATE(COUNTROWS(data), data[IsDB]="Yes")
    VAR _hf =
    CALCULATE(COUNTROWS(data), data[IsHF]="Yes")
    VAR _ht =
    CALCULATE(COUNTROWS(data), data[IsHT]="Yes")
    RETURN
    IF(_db+_hf+_ht>1, 1, 0)
)

 

i tried to expand your data sample:

FreemanZ_0-1672749889588.png

and verified the measure with a card visual:

FreemanZ_1-1672749959712.png

AlB
Community Champion
Community Champion

Hi @hana123 

See it all at work in the attached file.

Best to unpivot the columns to get a more manageable table structure first. 

Then you can create a measure for the number of patients:

MoreThan1DiseaseFlag = 
VAR aux_ =
    CALCULATE ( DISTINCTCOUNT ( Table1[Diagnosis] ), Table1[Result] = "Yes" ) > 1
RETURN
    IF ( aux_, 1, 0 )

 that uses this other measure:

NumPatientsWithMoreThan1Disease = 
SUMX ( DISTINCT ( Table1[ID] ), [MoreThan1DiseaseFlag] )

You can also use [MoreThan1DiseaseFlag] to show in a table visual the list of patients with more than one disease, by using the measure as a table visual and selecting it to show when the value is 1

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.