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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Belle2015
Helper I
Helper I

Count of machines in each Process

Hi,

I have had help to create the below DAX measure but the last part in orange is not working the way I need it too. 

I have a list of Machines that each fall into a certain process, there may be more than one machine in each process, what I need is a calculation I can use in the below where I need to divide the total scrap by the number of machines that come under the same process as at the minute the calculation is only dividing it by the total number of processes

Excel Data 

Power Bi example 

 

Allocated Scrap =
VAR CurrentProcess = 'Work Order Value'[Process]
VAR MachineWork = 'Work Order Value'[Work Value]
VAR TotalProcessWork =
    CALCULATE(
        SUM('Work Order Value'[Work Value]),
        ALLEXCEPT('Work Order Value', 'Work Order Value'[Process])
    )
VAR MachineCount =
    CALCULATE(
        COUNTROWS('Work Order Value'),
        ALLEXCEPT('Work Order Value', 'Work Order Value'[Work Value])
    )
VAR TotalScrap = CALCULATE(
        SUM('Scrap'[Value Scrapped]),
        ALLEXCEPT('Scrap', 'Scrap'[Process])
    )

RETURN
IF(
    TotalProcessWork > 0,
    TotalScrap * (MachineWork / TotalProcessWork),
    TotalScrap / MachineCount
)
1 ACCEPTED SOLUTION
burakkaragoz
Community Champion
Community Champion

Hi @Belle2015 ,

 

If you want to divide total scrap by the number of machines in each process (not by the number of total processes), your MachineCount measure needs to count the distinct machines for the current process.

Try changing your MachineCount to this:

dax
 
MachineCount =
CALCULATE(
    DISTINCTCOUNT('Work Order Value'[Machine]),
    ALLEXCEPT('Work Order Value', 'Work Order Value'[Process])
)

Then use:

dax
 
TotalScrap / MachineCount

This way, MachineCount will return the number of unique machines for each process, so your calculation will divide total scrap by the correct number.

Let me know if this helps or if you need to tweak it for your model!

View solution in original post

4 REPLIES 4
Belle2015
Helper I
Helper I

Hi @burakkaragoz ,

Thanks so much this worked perfectly 🙂

@Belle2015 ,Happy to help! If you run into anything else, feel free to ask.
Thanks for the feedback! 😊

HI @burakkaragoz , 

 

I ran into a problem when I went to use this in my actual data where I want to apply a date filter to see the values by month, I hadnt included the dates in my sample data, would I need to write something into the calculation to have it calculating by the date as at the minute it gets the total of scrap by process correct but when you split it out by the date the values by the date are not correct. 

Example Power Bi 

Any help would be appreciated.

Bronagh

burakkaragoz
Community Champion
Community Champion

Hi @Belle2015 ,

 

If you want to divide total scrap by the number of machines in each process (not by the number of total processes), your MachineCount measure needs to count the distinct machines for the current process.

Try changing your MachineCount to this:

dax
 
MachineCount =
CALCULATE(
    DISTINCTCOUNT('Work Order Value'[Machine]),
    ALLEXCEPT('Work Order Value', 'Work Order Value'[Process])
)

Then use:

dax
 
TotalScrap / MachineCount

This way, MachineCount will return the number of unique machines for each process, so your calculation will divide total scrap by the correct number.

Let me know if this helps or if you need to tweak it for your model!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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