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

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

Reply
Khomotjo
Helper II
Helper II

Measure between 2 tables with a many to many relationship

Hello everyone,

 

I have 2 tables : one containes orders picked and the others contains open orders. I want to create a measure to calculate percentage picked on total orders. 

 

I created a relationship between the two tables ( many to many on date) and calculated the percentage as :

 

Percentage _Picked = Calculate( Total_Picked/Total_Orders)

Total_Picked is a measure in Table 1 and Total_Orders is a measure in Table 2.

 

For some reason the data is not pulling through correctly when I visusalise using date fields from either one of the tables.

 

 

I am trying to visualise the percentage picked  for each day.

1 ACCEPTED SOLUTION
Bibiano_Geraldo
Super User
Super User

Hi @Khomotjo ,
You should avoid use the Many-to-Many Relationship which can cause unexpected filtering behavior.

 

You can achieve that by creating a Calendar Table if not already available, and link this Calendar table to both Orders_Picked and Open_Orders tables using a one-to-many relationship on Date.

Calendar = ADDCOLUMNS(
    CALENDAR(MIN('Orders_Picked'[Date]), MAX('Open_Orders'[Date])),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "YYYY-MM"),
    "MonthName", FORMAT([Date], "MMMM"),
    "Day", DAY([Date])
)

 

Now instead of relying on a direct many-to-many relationship, use the Calendar table as the filtering context:

Percentage_Picked = 
VAR Total_Picked = CALCULATE(
    SUM('Orders_Picked'[Picked_Orders]),
    USERELATIONSHIP('Calendar'[Date], 'Orders_Picked'[Date])
)

VAR Total_Orders = CALCULATE(
    SUM('Open_Orders'[Total_Orders]),
    USERELATIONSHIP('Calendar'[Date], 'Open_Orders'[Date])
)

RETURN
DIVIDE(Total_Picked, Total_Orders, 0)

 

View solution in original post

5 REPLIES 5
Bibiano_Geraldo
Super User
Super User

Hi @Khomotjo ,
You should avoid use the Many-to-Many Relationship which can cause unexpected filtering behavior.

 

You can achieve that by creating a Calendar Table if not already available, and link this Calendar table to both Orders_Picked and Open_Orders tables using a one-to-many relationship on Date.

Calendar = ADDCOLUMNS(
    CALENDAR(MIN('Orders_Picked'[Date]), MAX('Open_Orders'[Date])),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "YYYY-MM"),
    "MonthName", FORMAT([Date], "MMMM"),
    "Day", DAY([Date])
)

 

Now instead of relying on a direct many-to-many relationship, use the Calendar table as the filtering context:

Percentage_Picked = 
VAR Total_Picked = CALCULATE(
    SUM('Orders_Picked'[Picked_Orders]),
    USERELATIONSHIP('Calendar'[Date], 'Orders_Picked'[Date])
)

VAR Total_Orders = CALCULATE(
    SUM('Open_Orders'[Total_Orders]),
    USERELATIONSHIP('Calendar'[Date], 'Open_Orders'[Date])
)

RETURN
DIVIDE(Total_Picked, Total_Orders, 0)

 

Khomotjo
Helper II
Helper II

Thanks @bhanu_gautam , I think the issue is in the relationship. I tried linking the tables on a different field(same data type) but the  results are still the same. Values from one of the tables  are pulling through as constant numbers.

Share the relationship or sample data with us




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks @bhanu_gautam , sorted. I followed the troubleshooting guide  available online.

bhanu_gautam
Super User
Super User

@Khomotjo Verify that the relationship between the two tables is correctly established on the date field

 

Then create measures 

Total_Picked = SUM(Table1[PickedOrders])
Total_Orders = SUM(Table2[OpenOrders])

 

Create a measure to calculate the percentage of picked orders

Percentage_Picked = DIVIDE([Total_Picked], [Total_Orders], 0)

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
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