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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
dblw
New Member

How to calculate average profit ONLY when the product has been bought and sold in selected time.

Hello. 

 

I need to calculate the average profit of per product and in general in the selected time period. It is for a scrap business that buys scrap and then sells it forward. However, I only want to calculate profits for a product that has been bought AND sold in the selected period, because otherwise it will calculate a loss if a product has been recently bought in the selected time period but not sold. Now I have created a DAX formula that can calculate this on single products. Formula looks like this: 

Kate keskimäärin =
IF(
    NOT(ISBLANK([Ostot keskimäärin €/T])) && NOT(ISBLANK([Myynti keskimäärin €/T])),
    [Myynti keskimäärin €/T] - Ostot[Ostot keskimäärin €/T],
    BLANK()
)
Where "Ostot keskimäärin €/T" is average buying price and "Myynti keskimäärin €/T" is average sales price. It works and calculates this on single products but when it comes to the overall average on all the products it calculates also the ones that how been bought but not sold and vice versa. 
 Näyttökuva (80).png
As you can see in this table the total is calculated falsley since it includes everything. Does anybody know how I can get the average profit in total? It doesnt necessarily have to be visible in the table but I need the calculation to show the average profit All help will be appriciated. 
1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @dblw ,

 

try like:

Profit =
AVERAGEX(
    FILTER(
        tablename,
        NOT ISBLANK([buyingprice])
            &&NOT ISBLANK([sellingprice])
    ),
    [sellingprice] - [buyingprice]
)

View solution in original post

2 REPLIES 2
FreemanZ
Super User
Super User

hi @dblw ,

 

try like:

Profit =
AVERAGEX(
    FILTER(
        tablename,
        NOT ISBLANK([buyingprice])
            &&NOT ISBLANK([sellingprice])
    ),
    [sellingprice] - [buyingprice]
)

This worked. Thank you!

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.