Forum Discussion

Hesham121's avatar
Hesham121
Regular Visitor
2 years ago
Solved

DAX Sum Values based on 3 different tables criteria

Hello Dears,

 

I've the below data set and I want to create a measure that calculate total number of trips with the below critera:

 

- Sum 'DR_DUTIES'[# Of Trips]

If

'ROSTER DATABASE'[DATE] = 'APP_TT'[Date]

&

'APP_TT'[Applied TT] = 'DR_DUTIES'[TimeTable]

'DR_DUTIES'[Driving Duty] = 'ROSTER DATABASE'[Activity]

 

I need to SUM the # Of Trips and total Driving Hours per Employee based on Date, Activity, and Applied Timetable

 

1- DR_DUTIES Table:

 

Driving DutyTimeTable# Of TripsDriving Hours
M-01Ph3BTTR_TH_GIZA66:52:57 AM
M-02Ph3BTTR_TH_GIZA55:47:14 AM
E-01Ph3BTTR_TH_GIZA55:30:41 AM
E-02Ph3BTTR_TH_GIZA66:47:20 AM
M-01Ph3A_WE_LUXOR54:18:32 AM
M-02Ph3A_WE_LUXOR65:13:27 AM
E-01Ph3A_WE_LUXOR65:13:27 AM
E-02Ph3A_WE_LUXOR65:13:27 AM
M-01Ph3BTTR_WD_ASWAN55:29:32 AM
M-02Ph3BTTR_WD_ASWAN65:04:59 AM
E-01Ph3BTTR_WD_ASWAN66:34:00 AM
E-02Ph3BTTR_WD_ASWAN65:05:30 AM

 

2- Applied TT Table:

 

DateApplied TT
01-Jun-23Ph3BTTR_TH_GIZA
02-Jun-23Ph3BTTR_TH_GIZA
03-Jun-23Ph3BTTR_WD_ASWAN
04-Jun-23Ph3A_WE_LUXOR
05-Jun-23Ph3BTTR_TH_GIZA
06-Jun-23Ph3A_WE_LUXOR
07-Jun-23Ph3BTTR_WD_ASWAN
08-Jun-23Ph3BTTR_WD_ASWAN

 

3- ROSTER DATABASE Table:

 

CODEDateActivity
Emp0101-Jun-23E-02
Emp0102-Jun-23E-01
Emp0103-Jun-23M-02
Emp0104-Jun-23M-01
Emp0105-Jun-23E-02
Emp0106-Jun-23E-01
Emp0107-Jun-23M-02
Emp0108-Jun-23M-01

 

Expected Results should be

 

45 Trips and 43:32 Driving hours during the period 1-Jun-23 to 8-Jun-23 for the Emp01

3 Replies

  • That seems to be straightforward, you should be able to use data model and TREATAS or USERELATIONSHIP to handle that.  What have you tried and where are you stuck?

     

     

    • Hesham121's avatar
      Hesham121
      Regular Visitor

      I've tried to connect the data model, but it wasn't able to get the correct results and I don't why... maybe there are a problem with the data modeling, Can you suggest the best connection between tables please?