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
Anonymous
Not applicable

Calculate sales over different rows

Hi all,

 

I've a question. In PBI i want to assign sales based on hours to the car_number. Problem is that i have only one row where the sales has been filled in, look below:

 

CORPBI_1-1692679963303.png

How can i solve this?

Regards, Cor

 

6 REPLIES 6
Anonymous
Not applicable

Hi Prateek97,

 

Thanks for your answer, it works for almost all the transactions. But what code do i have to add to this code when the hours are zero and/or the sales are zero? Because i want when the hours are zero the original sales and when the sales are zero i want 0. Hope this is possible. 

Thanks in advance. 

Anonymous
Not applicable

Anyone an idea @Prateek97 ?

Hi @Anonymous ,

 

You just need to add a IF condition at  the end.

 

New Sales = 

var og_sales = CALCULATE(SUM('Car Test'[Sales]),ALLEXCEPT('Car Test','Car Test'[OrderKey]))

var total_hours = CALCULATE(SUM('Car Test'[Hours]),ALLEXCEPT('Car Test','Car Test'[OrderKey]))

var new_sales = (og_sales/total_hours)*'Car Test'[Hours]

return

IF(og_sales=0,0,IF(total_hours=0,og_sales,new_sales))
 
Let me know if it works.
Anonymous
Not applicable

Thanks. The problem is for 99% solved. I've test it and sometime it get some weird numbers: 

 

CORPBI_0-1692973483854.png

 

How can i solve this @Prateek97?

HI @Anonymous ,

 

The answer seems correct.

Total Sales = 616.24

Total Hours = 8.25

Sales per Hour = 74.695

Row1 = 74.695 * 2 = 149.3915

Row2 = 74.695* 6.25 = 466.8485

 

Please let me know where is the error

Prateek97
Resolver III
Resolver III

Hi @Anonymous ,

 

Please try the following DAX.

 

New Sales = 

var og_sales = CALCULATE(SUM('Car Test'[Sales]),ALLEXCEPT('Car Test','Car Test'[OrderKey]))

var total_hours = CALCULATE(SUM('Car Test'[Hours]),ALLEXCEPT('Car Test','Car Test'[OrderKey]))

var new_sales = (og_sales/total_hours)*'Car Test'[Hours]

return

new_sales

 

Prateek97_0-1692681506798.png

 

Please mark this as a solution. If it works for 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.

Top Solution Authors
Top Kudoed Authors