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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ChristianR
Frequent Visitor

Dax - How to calculate average based on quantity on each row.

I am trying to calculate an average based on number of transactions and #days to complete.  

The dataset looks like

 

TX_CNT           DAYS_TO_COMPLETE

    5                             13

    2                              5

    1                              3

 

So the average days to complete by transaction is 9.75 = ((13*5)+(5*2)+(3x1)) / (5+2+1)

I have this data in one table coming from SQL.  

How can I calculate the average across rows while considering the TX_CNT.

FYI I have other attributes in the table which I'll use for legend, slicers etc... but I am trying to create a measure I can use.

 

Thank you!

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @ChristianR 

If your table contains the two columns shown, you can write a measure like this to perform the weighted-average calculation:

Average days =
DIVIDE (
    SUMX (
        YourTable,
        YourTable[TX_CNT] * YourTable[DAYS_TO_COMPLETE]
    ),
    SUM ( YourTable[TX_CNT] )
)

 Does that work for you?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hello @ChristianR ,

Create a below two measures

Measure = MAX(Table[TX_CNT])*MAX(Table[DAYS_TO_COMPLTETE])
 
Measure 2 = [Measure]/SUM(Table[TX_CNT])
OwenAuger
Super User
Super User

Hi @ChristianR 

If your table contains the two columns shown, you can write a measure like this to perform the weighted-average calculation:

Average days =
DIVIDE (
    SUMX (
        YourTable,
        YourTable[TX_CNT] * YourTable[DAYS_TO_COMPLETE]
    ),
    SUM ( YourTable[TX_CNT] )
)

 Does that work for you?

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

@OwenAuger perfect!   I'm still getting my bearings around DAX.

Thank you.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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