cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
android1 Member
Member

Divide sum of one column by the count of another

Hi,

 

I have a column LoS which is in number format with a sum total. The other column, ID, is a Count of text values.

 

Is it possible to divide LoS by ID?

 

Gerry

2 ACCEPTED SOLUTIONS

Accepted Solutions
malagari Member
Member

Re: Divide sum of one column by the count of another

Sure - you can do this as a DAX measurement.  Unless I'm misunderstanding your post, it should be simple as:

 

Measure = LoS / ID

And if you're worried about the possibility that 'ID' will be zero, you want to account for the divide-by-zero case with:

Measure = DIVIDE(LoS, ID, 0)


However, if you need the aggregations (sum of LoS, count of ID) done in the measurement:

 

Measure = DIVIDE( SUM(LoS), COUNT(ID), 0 )

 

 And alternately, if the ID is text values, you can use COUNTROWS(ID) instead.

Dan Malagari
Consultant at Headspring

View solution in original post

Phil_Seamark Super Contributor
Super Contributor

Re: Divide sum of one column by the count of another

So make sure you click the "New Measure" button on the modelling tab.

 

or right click the table name and choose "New Measure" and add the above code by @malagari

 

Measure = DIVIDE( SUM(LoS), COUNT(ID), 0 )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
malagari Member
Member

Re: Divide sum of one column by the count of another

Sure - you can do this as a DAX measurement.  Unless I'm misunderstanding your post, it should be simple as:

 

Measure = LoS / ID

And if you're worried about the possibility that 'ID' will be zero, you want to account for the divide-by-zero case with:

Measure = DIVIDE(LoS, ID, 0)


However, if you need the aggregations (sum of LoS, count of ID) done in the measurement:

 

Measure = DIVIDE( SUM(LoS), COUNT(ID), 0 )

 

 And alternately, if the ID is text values, you can use COUNTROWS(ID) instead.

Dan Malagari
Consultant at Headspring

View solution in original post

Phil_Seamark Super Contributor
Super Contributor

Re: Divide sum of one column by the count of another

So make sure you click the "New Measure" button on the modelling tab.

 

or right click the table name and choose "New Measure" and add the above code by @malagari

 

Measure = DIVIDE( SUM(LoS), COUNT(ID), 0 )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

android1 Member
Member

Re: Divide sum of one column by the count of another

Thanks alot. What I was doing wrong was I had the result to display in a KPI visual rather than a Card so I thought LoS / ID wasn't correct.

 

Thanks again.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 100 members 1,380 guests
Please welcome our newest community members: