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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Canadf
Frequent Visitor

SUM per group, and then divide with the total

I have a table like

 

Machine

time
cutter10
cutter20
cutter30
weld1
weld2

Then I calculate the total of the time column, 63.

What I need, is to add the times grouping the machine, so cutter would have 60 minutes, and weld 3, and then I need to divide these two numbers against the total of the column time, giving me the ratio each one has.

MachineTimeRatio
cutter600.95
weld3

0.05

Ive been trying using Calculate and sum, but when I use sum in different measures, it just divides the total against the total so  get 1. 

I thought of the option of using a measure for each machine, but fro using a graph later it didn't work because there are more achines, and the measure doesn't relate to that machine

6 REPLIES 6
v-yilong-msft
Community Support
Community Support

Hi @Canadf ,

I create a table as you mentioned.

vyilongmsft_0-1714364511692.png

Then I create a measure and a calculated column.

Measure = SUM('Table'[time])
Column = SUM('Table'[time])

vyilongmsft_1-1714365109937.png

Finally I create another measure and you will get what you want.

Measure 2 = DIVIDE('Table'[Measure],MAX('Table'[Column]))

vyilongmsft_2-1714365774204.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

This almost worked, but the new "Column" is not being affecte by filters, how can I make it so the filters (I have one to filter the date and one to filter the machine) affect the sum column?

Hi @Canadf ,

It seems that there is a date column in your data, can you show me more information about your table or give me your .pbix file?

 

 

Best Regards

Yilong Zhou

AnalyticsWizard
Solution Supplier
Solution Supplier

@Canadf 

It sounds like you want to create a ratio of each machine's time against the total time for all machines in Power BI. Here's a step-by-step way to achieve this using DAX:

1. First, create a measure to calculate the total time for all machines.

Total Time = SUM(Table[time])

2. Next, create a measure to calculate the total time per machine. This measure groups the time by each machine.

Machine Time = CALCULATE(SUM(Table[time]), ALLEXCEPT(Table, Table[Machine]))

3. Finally, create a measure to calculate the ratio of each machine's total time to the total time.

Time Ratio = DIVIDE([Machine Time], [Total Time])

With these measures, you can add these to a table visualization:
- Drag the `Machine` field and the `Machine Time` and `Time Ratio` measures into your table or chart.

This setup should dynamically calculate the time and ratios for all machines, and it will update as you add more machine types or data points. This avoids the need for creating individual measures for each machine, which as you've identified, can be limiting in graphical representations.

 

If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

mh2587
Super User
Super User

Ratio Measure = // Try this
VAR TotalTime = SUM(Table[time])
VAR TotalTimePerMachine =
    SUMX(
        VALUES(Table[Machine]),
        CALCULATE(SUM(Table[time]))
    )
RETURN
    DIVIDE(TotalTimePerMachine, TotalTime)

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Canadf
Frequent Visitor

Thank you, bu it didn't work. It does the same as I tried, the ratio is 1 for evey machine, it's doin the sum per machine

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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