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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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