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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Polar_A
Helper I
Helper I

Dax Formula calculations

Hi

I need some help please. My Dax measures counts are not working dependently to one another. i have done a male and female count, but it is only taking to account either male or either female and not giving me a total count. Its as if it has taken the first value in the source whereas I want the total value.

Polar_A_0-1722981988355.png

Herre are some of my Dax measures that I used:

MaleCount =

CALCULATE(

    COUNTROWS(Patients),Patients[Gender] = "Male",

    FILTER(ALL(Prescriptions),Prescriptions[Therapy] = MAX(Prescriptions[Therapy])),

    FILTER(ALL(Patients),Patients[Referring Establishment] = MAX(Patients[Referring Establishment])))

 

FemaleCount =

CALCULATE(

    COUNTROWS(Patients),Patients[Gender] = "Female",

    FILTER(ALL(Prescriptions),Prescriptions[Therapy] = MAX(Prescriptions[Therapy])),

    FILTER(ALL(Patients),Patients[Referring Establishment] = MAX(Patients[Referring Establishment])))

 

Average Age = CALCULATE(

    AVERAGE(Patients[Age]),

    FILTER(ALL(Prescriptions),Prescriptions[Therapy] = MAX(Prescriptions[Therapy])),

    FILTER(ALL(Patients),Patients[Referring Establishment] = MAX(Patients[Referring Establishment])))

 

Registered =

CALCULATE(

    COUNTROWS(Patients),Therapy[Created On],

    FILTER(ALL(Prescriptions),Prescriptions[Therapy] = MAX(Prescriptions[Therapy])),

    FILTER(ALL(Therapy),Therapy[NHS/Hospital] = MAX(Therapy[NHS/Hospital])),

    FILTER(ALL(Patients),Patients[Referring Establishment] = MAX(Patients[Referring Establishment])))

Thank you




1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Polar_A ,

Base on your description, it seems like the total values of FemaleCount and MaleCount are incorrect. You can create another two new measures as below and replace the measure [MaleCount] and [FemaleCount] with these two new measures.

New_FemaleCount =
SUMX (
    VALUES ( Prescriptions[Therapy] ),
    SUMX ( VALUES ( Patients[Referring Establishment] ), [FemaleCount] )
)
New_MaleCount =
SUMX (
    VALUES ( Prescriptions[Therapy] ),
    SUMX ( VALUES ( Patients[Referring Establishment] ), [MaleCount] )
)

In addition, you can refer the following links to try to solve your problem...

Why Your Total Is Incorrect In Power BI - The Key DAX Concept To Understand

Dax for Power BI: Fixing Incorrect Measure Totals

 

If the above ones can't help you figure out, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @Polar_A ,

Base on your description, it seems like the total values of FemaleCount and MaleCount are incorrect. You can create another two new measures as below and replace the measure [MaleCount] and [FemaleCount] with these two new measures.

New_FemaleCount =
SUMX (
    VALUES ( Prescriptions[Therapy] ),
    SUMX ( VALUES ( Patients[Referring Establishment] ), [FemaleCount] )
)
New_MaleCount =
SUMX (
    VALUES ( Prescriptions[Therapy] ),
    SUMX ( VALUES ( Patients[Referring Establishment] ), [MaleCount] )
)

In addition, you can refer the following links to try to solve your problem...

Why Your Total Is Incorrect In Power BI - The Key DAX Concept To Understand

Dax for Power BI: Fixing Incorrect Measure Totals

 

If the above ones can't help you figure out, please provide some raw data in your tables(exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.