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
Johnmag
Regular Visitor

Calculate monthly distribution between two tables

Hi, 
I've been trying to create a report which estimates the monthly distribution based on two tables.

 

Table 1 contains Year-Month, country and weight based on shipping data.  

Year-Month      Country      Weight Kg   
2021-01      Norway   

   15

2021-01   Canada      2
2021-02   Norway   10
2021-02   Brazil   3

 

Table 2 contains Year-Month, weight, and attributes based on transactions. 

Year-Month   Weight Kg   Attribute 1   Attribute 2   Attribute 3
2021-01   12   A   A

   B

2021-01   5   B   C   A
2021-02   3    C   B   A
2021-02   9    B   B   B

 

I'm trying to estimate the distribution of each attribute with each country based weight distribution per month.  
My plan is to calculate the total attribute weight per month, get a ratio and then distribute it to each country.

The total weight per month doesn't need to add upp to the toal attribute weight per month, only the ratios are important. 

 

In this example I want the following: 
2021-01: Total attribute weight 17 Kg, 12/17 has [A,A,B] and 5/17 has [B,C,A] 
2021-02: Total attribute weight 12 Kg, 3/12 has [C,B,A] and 9/12 has [B,B,B] 

The end table should then show 

Year-month   Country   Attribute Weight Kg   Attribute 1   Attribute 2    Attribute 3
2021-01   Norway   12*(12/17)    A   A   B
2021-01   Norway   12*(5/17)   B   C   A
2021-01   Canada   5*(12/17)    A   A   B
2021-01   Canada   5*(5/17)    B   C   A
2021-02   Norway   10*(3/12)    C   B   A
2021-02   Norway   10*(9/12)   B   B   B
2021-02   Brazil   3*(3/12)    C   B   A
2021-02   Brazil   3*(9/12)   B   B   B


Any help regarding this would be greatly apprechiated!

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @Johnmag ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want.

1. Create a relationship between Table 1 and Table 2 base on the field Year-Month

yingyinr_0-1651828038722.png

2. Create a measure as below

Attribute Weight Kg = 
VAR _selym =
    SELECTEDVALUE ( 'Table 1'[Year-Month] )
VAR _selcountry =
    SELECTEDVALUE ( 'Table 1'[Country] )
VAR _t2sqty =
    CALCULATE (
        SUM ( 'Table 2'[Weight Kg] ),
        FILTER ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Year-Month] = _selym )
    )
RETURN
    SUM ( 'Table 1'[Weight Kg] )
        * ( DIVIDE ( SUM ( 'Table 2'[Weight Kg] ), _t2sqty ) )

yingyinr_1-1651828190874.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
daXtreme
Solution Sage
Solution Sage

Where do you want to do this? In Power Query or DAX? I suggest you do it in Power Query.

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