cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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
Super User

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
Blog
3 REPLIES 3
Responsive Resident

Hello @ChristianR ,

Create a below two measures

Measure = MAX(Table[TX_CNT])*MAX(Table[DAYS_TO_COMPLTETE])

Measure 2 = [Measure]/SUM(Table[TX_CNT])
Super User

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
Blog
Frequent Visitor

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

Thank you.

Announcements

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.