Forum Discussion
SUM Column in Value Exists in Another Table
I have two datasets
Dataset 1
| ID | Hours | Job Type |
| 1 | 10 | Erect |
| 2 | 10 | Dismantle |
Dataset 2
| ID | Estimate Erect Hours | Estimate Dismantle Hours |
| 1 | 15 | 5 |
| 2 | 10 | 0 |
I want to create a measure that can do the following:
SUM column 'Hours' in dataset 1. But only if the hours relating to that ID and 'Job Type' are greater than 0 in dataset 2.
For example, dataset 1 shows 'ID' 1 has 10 'Hours' for a 'Job Type' Erect. Dataset 2 has 15 'Estimate Erect Hours' which is matching to the existing 'Job Type' shown in dataset 1 and is greater than 0 therefore 'Hours' in dataset 1 will be summed.
Many thanks,
Hi , Anonymous
According to your description, you want to get the sum of [Hours] according to the another table the job type hour > 0.
Here are the steps you can refer to :
(1)My test data is the same as yours.(2)We can create a measure like this:
Measure = var _t =ADDCOLUMNS( ALLSELECTED('Table 1') , "flag" , var _id = [ID] var _job=[Job Type] var _t = FILTER('Table 2' ,'Table 2'[ID] = _id) return IF( OR( _job = "Erect" && MAXX(_t, [Estimate Erect Hours])>0 ,_job = "Dismantle" && MAXX(_t, [Estimate Dismantle Hours])>0 ) , 1, 0)) return SUMX(_t ,IF([flag]=1,[Hours],0))(3)Then we can get the total:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
4 Replies
- Jacekk111
Helper I
Hi, You can easly make it by creation of properly bounding beetwen database 1 and database2 and in graph set a sum and graph filter making assumption based on database2
- AnonymousNot applicable
Thanks for your response. I am abit confused on how to achieve this.
I have tried
- creating a visual that sums hours in dataset 1
- Creating a relationship between ID in both datasets
- Filtering out the visual if 'Estimate Erect Hours' or 'Estimate Dismantle Hours' are greater than 0
This is not working as it doesnt look to see if the 'ID' in dataset 1 relates to a 'Job Type' erect or dismantle.
- v-yueyunzh-msft
Community Support
Hi , Anonymous
According to your description, you want to get the sum of [Hours] according to the another table the job type hour > 0.
Here are the steps you can refer to :
(1)My test data is the same as yours.(2)We can create a measure like this:
Measure = var _t =ADDCOLUMNS( ALLSELECTED('Table 1') , "flag" , var _id = [ID] var _job=[Job Type] var _t = FILTER('Table 2' ,'Table 2'[ID] = _id) return IF( OR( _job = "Erect" && MAXX(_t, [Estimate Erect Hours])>0 ,_job = "Dismantle" && MAXX(_t, [Estimate Dismantle Hours])>0 ) , 1, 0)) return SUMX(_t ,IF([flag]=1,[Hours],0))(3)Then we can get the total:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- AnonymousNot applicable
Thank you very much for taking the time to solve the problem!
You are a life saver 🙂