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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

New measure to combine two calculations

Hi All,

 

I would like to comibine the following two mesures (Average / SUM) based on county:

 

IF 

data_merged[crashid]="LEA"

then

crashdeathcount_agg = SUMX(DISTINCT(data_merged[crashid]),CALCULATE(AVERAGE(data_merged[crashdeathcount])))
else 
crashdeathcount_agg = SUMX(DISTINCT(data_merged[crashid]),CALCULATE(SUM(data_merged[crashdeathcount])))
 
Any suggestions?
 
Thanks in advance!
Joan
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

If you already have the two measure calculated you just need to do the following code:

IF (SELECTEDVALUE(data_merged[crashid])="LEA" , crashdeathcount_agg , crashdeathcount_agg )

If you don't have the measures separated you should do:3

Measure =
IF (
    data_merged[crashid] = "LEA",
    crashdeathcount_agg
        = SUMX (
            DISTINCT ( data_merged[crashid] ),
            CALCULATE ( AVERAGE ( data_merged[crashdeathcount] ) )
        ),
    crashdeathcount_agg
        = SUMX (
            DISTINCT ( data_merged[crashid] ),
            CALCULATE ( SUM ( data_merged[crashdeathcount] ) )
        )
)

Without any data and specif details on your data model is difficult to give you a better answer.

 

If this doesn't wqork can you share a sample data and expected result.

 

Regards,

MFelix

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Drag CrashID to the row labels of your Table visual and write this measure

=IF(HASONEVALUE(data_merged[crashid]),IF(VALUES(data_merged[crashid])="LEA",SUMX(DISTINCT(data_merged[crashid]),CALCULATE(AVERAGE(data_merged[crashdeathcount]))),SUMX(DISTINCT(data_merged[crashid]),CALCULATE(SUM(data_merged[crashdeathcount])))),BLANK())

Hope this helps.


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

Hi @Anonymous ,

 

If you already have the two measure calculated you just need to do the following code:

IF (SELECTEDVALUE(data_merged[crashid])="LEA" , crashdeathcount_agg , crashdeathcount_agg )

If you don't have the measures separated you should do:3

Measure =
IF (
    data_merged[crashid] = "LEA",
    crashdeathcount_agg
        = SUMX (
            DISTINCT ( data_merged[crashid] ),
            CALCULATE ( AVERAGE ( data_merged[crashdeathcount] ) )
        ),
    crashdeathcount_agg
        = SUMX (
            DISTINCT ( data_merged[crashid] ),
            CALCULATE ( SUM ( data_merged[crashdeathcount] ) )
        )
)

Without any data and specif details on your data model is difficult to give you a better answer.

 

If this doesn't wqork can you share a sample data and expected result.

 

Regards,

MFelix

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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