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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
PBI_newuser
Post Prodigy
Post Prodigy

How to combine 2 tables into 1

Hi, I want to calculate the total expense per job by month based on the below 2 tables.

For example, the total expense for WM in January is $100 and Job count in January is 2. Hence, $100/2 = $50.

 

For Product = Non-WM, I would like to take the total expense divide by Total Job Count for Product = WM.

Eg. In March, total expense for Non-WM is $300 and total job count for WM = 1, so the expense per job = $300/1 = $300

Same goes to Product = Non-REF, I would take the total job count for product = REF as denominator.

 

Table A:

DateProductEmployeeExpense
01/01/2021WMABC100
02/25/2021REFBCD200
03/24/2021Non-WMCDE300
05/12/2021Non-REFEFG400

 

Table B:

DateJob No.Product
01/05/2021Job-123WM
01/20/2021Job-234WM
02/12/2021Job-345WM
03/23/2021Job-456REF
05/03/2021Job-457REF
1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

I'm not sure if this is what you are after, and I have had to modify your tables to showcase the measures, but here we go...

With this model:
Model.JPG

 and these measures:

Sum Expense = SUM('Table A'[Expense])
Job Number = DISTINCTCOUNT('Table B'[Job No.])
Expense per job = 
VAR NumJobs = DISTINCTCOUNT('Table B'[Job No.])
RETURN
DIVIDE([Sum Expense], NumJobs)
Non-REF from REF =
VAR REF =
    CALCULATE (
        [Job Number],
        'Dim Product'[Product] = "REF",
        ALL ( 'Dim Product' )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Dim Product'[Product] ) = "Non-REF",
        DIVIDE ( [Sum Expense], REF )
    )
Non-WM from WM =
VAR WM =
    CALCULATE ( [Job Number], 'Dim Product'[Product] = "WM", ALL ( 'Dim Product' ) )
RETURN
    IF (
        SELECTEDVALUE ( 'Dim Product'[Product] ) = "Non-WM",
        DIVIDE ( [Sum Expense], WM )
    )

You get this...

result.JPG

 

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

2 REPLIES 2
PaulDBrown
Community Champion
Community Champion

I'm not sure if this is what you are after, and I have had to modify your tables to showcase the measures, but here we go...

With this model:
Model.JPG

 and these measures:

Sum Expense = SUM('Table A'[Expense])
Job Number = DISTINCTCOUNT('Table B'[Job No.])
Expense per job = 
VAR NumJobs = DISTINCTCOUNT('Table B'[Job No.])
RETURN
DIVIDE([Sum Expense], NumJobs)
Non-REF from REF =
VAR REF =
    CALCULATE (
        [Job Number],
        'Dim Product'[Product] = "REF",
        ALL ( 'Dim Product' )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Dim Product'[Product] ) = "Non-REF",
        DIVIDE ( [Sum Expense], REF )
    )
Non-WM from WM =
VAR WM =
    CALCULATE ( [Job Number], 'Dim Product'[Product] = "WM", ALL ( 'Dim Product' ) )
RETURN
    IF (
        SELECTEDVALUE ( 'Dim Product'[Product] ) = "Non-WM",
        DIVIDE ( [Sum Expense], WM )
    )

You get this...

result.JPG

 

I've attached the sample PBIX file





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi @PBI_newuser ,

 

Why using count of WM for Non-WM and count of REF for Non-REF?

 

Best Regards,

Jay

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 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.