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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Yenn
Frequent Visitor

Calculate the different hours between two tables

Hi @everyone,

I am trying to calculate the different hours between two tables but it's not working, what should I do in this case?

 

Table 2: 

Yenn_0-1691664493340.png

Table 1: 

Yenn_1-1691664532128.png

 When I typed the formula below, it shown: 

Hour comparison =
var _Table1 =SELECTEDVALUE(fHour[Hours])
var _Table2 =SELECTEDVALUE('fResults[Hour])
return
_Table2 - _Table1
 
Yenn_2-1691664864145.png

 

3 REPLIES 3
Yenn
Frequent Visitor

I already created the relationship "Many-to-Many" between two tables and I tried to using this formula but it didnt work. I want to describe in details two reports as the following:

+ Table 1 ( Hour report): each ID displayed the total hours for which operated everyday. Some IDs will repeat or they are added or removed depend on the business situation.

+ Table 2 ( Results): each ID displayed the total hours that customer spent everyday.

For example: On 19/01/2019, ID: BJ-01-01, Table 1 (Hour) = 21.37, Table 2 (Results) = 8.15

And the result I want to show:

Yenn_2-1691727417230.png

 

AmiraBedh
Most Valuable Professional
Most Valuable Professional

Can you please share your pbix file ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
AmiraBedh
Most Valuable Professional
Most Valuable Professional

Are you considering the ID in your calculation ?

Logically, I can calculate the diffrence in hours between the two tables for the same ID.

In that case you need to join the two tables on the IDs so that you can perform calculations on the corresponding rows.You can then calculate the difference in hours between the two tables for the corresponding IDs.

Create Relationships Between Tablesi f you haven't already, you might want to create a relationship between the tables using the common ID field.

and then :

Difference_in_Hours =
SUMX(
    Table1, // Assuming you want to iterate through Table1
    VAR RelatedRow = RELATEDTABLE(Table2) // Fetch related row from Table2
    VAR Hours1 = Table1[hours] // Get hours from Table1
    VAR Hours2 = SUMX(RelatedRow, Table2[hours]) // Get hours from related row in Table2
    RETURN Hours1 - Hours2 // Return the difference
)

 

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.