Reply
shalabh
Helper I
Helper I
Partially syndicated - Outbound

groupby count to find avg price

Hi,

 

I am trying to find the avg price per unit. 

The issue is my data can have an order ID with price borken, but quantity same.

 

For example

 

IDProductQtyPrice
Ax210
Ax220
Bx530
Cx320
Cx340

Order ID A - quantity is 2 and total price is 30 (it is split based on SKU). Given this, avg price for A is 30/2=15 

For the above data set, avg price is (120/10 = 12) : price is added, and qty is total for each ID divided by count of each ID

 

How can I write a DAX measure to compute this?

In excel, I would run a pivot and do it row wise for each ID. 

 

Please note, I would like to use a slicer on product later to find avg price by product. Hence summarizecolumns may not be the best way

 

Thanks!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Syndicated - Outbound

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

It is for creating a dax measure.

 

 

Jihwan_Kim_0-1710388636755.png

 

Jihwan_Kim_1-1710389366495.png

 

Avg price: = 
VAR _qty =
    SUMX (
        VALUES ( Data[Id] ),
        CALCULATE ( DIVIDE ( SUM ( Data[Qty] ), COUNTROWS ( Data ) ) )
    )
VAR _pricetotal =
    SUM ( Data[Price] )
RETURN
    DIVIDE ( _pricetotal, _qty )

 

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Syndicated - Outbound

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file whether it suits your requirement.

It is for creating a dax measure.

 

 

Jihwan_Kim_0-1710388636755.png

 

Jihwan_Kim_1-1710389366495.png

 

Avg price: = 
VAR _qty =
    SUMX (
        VALUES ( Data[Id] ),
        CALCULATE ( DIVIDE ( SUM ( Data[Qty] ), COUNTROWS ( Data ) ) )
    )
VAR _pricetotal =
    SUM ( Data[Price] )
RETURN
    DIVIDE ( _pricetotal, _qty )

 

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)