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

Sum one column and then divide against the count of another column

Hello, I have a column "Open" that lists the number of open positions and a column "Name" that I would like to have a total count of. The math formula would look like this. Open/Name*100=__%. I've set it up to work in Excel, but not sure how to enter it in power query since there are multiple calculations. Is it best to build from a blank query or advanced editor? Current status: Table.RowCount(Query 1) Any help would be appreciated. Thank you!

2 ACCEPTED SOLUTIONS

Hi @Anonymous ,

 

You can use this code:

[Open] / List.Count(#"Changed Type"[Name])

 

Capture.PNG

 

This DAX solution would be better to handle it:

Measure = DIVIDE(SUM('Table'[Open]), CALCULATE(DISTINCTCOUNT('Table'[Name]), ALL('Table')))
 
Measure 2 =
VAR _qtdeName = CALCULATE(DISTINCTCOUNT('Table'[Name]), ALL('Table'))
VAR _qtOpenPosition = SUM('Table'[Open])
RETURN DIVIDE(_qtdeName + _qtOpenPosition - _qtOpenPosition, _qtOpenPosition + _qtdeName)
 
Capture.PNG
 
 

 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

@Anonymous ,

 

You are inputing a DAX language in Power Query.

Try importing the table and try it creating measure.

 

Take a look at this file: Download PBIX 

 

This example only has DAX code, let me know if you still need to do it using Power Query.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

9 REPLIES 9
camargos88
Community Champion
Community Champion

Hi @Anonymous,

 

Try this one:

 

let
_open = [Open],
_name = [Name]
in
_open / List.Sum(Table.SelectRows(#"Changed Type", each [Name] = _name)[Open]) * 100

 

Capture.PNG

 

The bold part is your step name before this new column.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Ricardo, 

 

Thank you. The synax worked, but it produced an error in the cell stating that it can't find column [Open]. I merged it as a query from another source, so the top is listed as [1.2 Open]. Would that change the formula?

 

Thank you!


Derek

@Anonymous ,

 

Can you post some example of your dataset ?



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Here you go. Ultimately I'll need two different final values. If I can just get one to work I want to continue learning and figure out the other one. Thank you!

 

% Open against Total Names (Open/(Name)*100 = __%

and 

% Open against Total Name and Open (Open/(Name+Open))*100 = __%

 

 

Name Open.JPG 

 

Open 1.2.JPG

@Anonymous ,

 

Can you explain the logic with an example using this data, please ?



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

There are (7) names, let's call them Employees and there are (3) Open positions. So out of a total of (10) positions, the company is 70% staffed. 

 

Open / (Active+Open) = % Staffed 

 

Does that help?

Hi @Anonymous ,

 

You can use this code:

[Open] / List.Count(#"Changed Type"[Name])

 

Capture.PNG

 

This DAX solution would be better to handle it:

Measure = DIVIDE(SUM('Table'[Open]), CALCULATE(DISTINCTCOUNT('Table'[Name]), ALL('Table')))
 
Measure 2 =
VAR _qtdeName = CALCULATE(DISTINCTCOUNT('Table'[Name]), ALL('Table'))
VAR _qtOpenPosition = SUM('Table'[Open])
RETURN DIVIDE(_qtdeName + _qtOpenPosition - _qtOpenPosition, _qtOpenPosition + _qtdeName)
 
Capture.PNG
 
 

 



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Anonymous
Not applicable

Ricardo, 

 

I changed the table name and here is what I'm getting back. I've played around with it a few different ways, but have been unable to get rid of the error. Any thoughts? 

 

Total Staff.JPG

@Anonymous ,

 

You are inputing a DAX language in Power Query.

Try importing the table and try it creating measure.

 

Take a look at this file: Download PBIX 

 

This example only has DAX code, let me know if you still need to do it using Power Query.



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



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.

Top Solution Authors
Top Kudoed Authors