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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Group BY function Calculation

Hello,

I have two tables: Revenue and Hours. Both these tables have project ID.

 

Revenue Table:

Revenue.PNG

 

Work Hours:

Work Hours.PNG

 

I have joined both the tables via Project, Month, and Year. The join was Many to Many.

 

How should I proceed to get total revenue by project, year, and month divided by total hours by project, year, and month? (As Measure if that's easier or a new column in a third table)

Example efficiency for A1for the month of May is =20/10.

 

I tried "group by" function in edit query of power BI but that function deletes the Journal ID column. I would like to keep all the columns if possible.

 

5 REPLIES 5
v-diye-msft
Community Support
Community Support

Hi @Anonymous 

 

If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly. If not, please kindly elaborate more. thanks!

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
jdbuchanan71
Super User
Super User

@Anonymous 

I think you are going to want to change the structure of your data a bit.  You should have a projects table and a date table both of which would link to the hours and revenue table.

jdbuchanan71_0-1594436117320.png

once you have that it is pretty straight forward to get the views you are looking for.

jdbuchanan71_1-1594436168996.png

I have attached a sample file that shows how to get the date field using the year and month and how to generate a date table.

 

 

 

Anonymous
Not applicable

@jdbuchanan71  Thank you for the reply, Why do we need a seperate project table?

You use the project table to view information at the project level.  because it sits above both hours and revenue the filters from the project table flow down to both.  It's called a start schema and it's how PowerBI is designed to work.  You have lookup tables like the Dates table and the Projects table that hold categorical  attributes like project name, project description, project owner, project start date, etc.  and you have fact tables like hours and revenue.  The fact tables typically hold numeric values.

In my sample visual the project column is from the project table, that way the hours and revenue amount from those fact tables work correctly when viewed together at the project level.

lbendlin
Super User
Super User

If you want to keep all columns then you cannot use GroupBy.

 

Write a measure that calculates the ratio. Here is one option

 

Ratio = 
var p=selectedvalue(Revenue[Project])
var y=selectedvalue(Revenue[Year])
var m=selectedvalue(Revenue[Month])
var rev=calculate(sum(Revenue[Revenue]),allselected(Revenue),Revenue[Project]=p,Revenue[Year]=y,Revenue[Month]=m)
var hrs=calculate(sum(Hours[hours]),allselected(Hours),Hours[Project]=p,Hours[Year]=y,Hours[Month]=m)
return divide (rev,hrs)

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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