Forum Discussion
Calculate and filter using multiple tables
Hello,
I have two data tables, one (I'll call it table 1) for occurrences by date, product, production line, and how long it lasted. And another one with the campaign with start and end date, line and product (I'll call it table 2)
I need to sum the amount of time those occurrences lasted by campaing.
I tried assigning for each occurrence a code for it's campaing ("line & product code & startdate"). But couldn't make it work, needed to check the line and product combination and if the date of the occurrence was in the interval of the campaign. Another way was to filter by this two conditions directly at the campaign table on a new column.
But still, I don't know how it could be done.
Could somebody help me with this problem, pls?
Thanks!
This calculated column formula in the Campaigns table works
=CALCULATE(SUM(Occurences[Duration]),FILTER(Occurences,Occurences[Line]=EARLIER(Campaign[Line])&&Occurences[Product]=EARLIER(Campaign[Product])&&Occurences[Date]>=EARLIER(Campaign[Start date])&&Occurences[Date]<=EARLIER(Campaign[End Date])))Hope this helps.
14 Replies
- dhruvinushahResponsive Resident
Hi, It seems your second table has the product and line fields. All you need to do is create a relationship between table 1 and table 2 on the common fields like Line or Product.
Doing so will allow your fields from tablw 2 to be related to table 1.
After creating the relationship you can create a table with Campaign, Product and Sum of [how long occurences lasted] to get your result.- ojferreiraFrequent Visitor
I have a variety of products, 14 lines and the campaigns last only some days, therefore, I have many entries for campaigns, and some products repeat themselfs on the same line duing the year. Therefore, I needed something like I explained:
- Relate the occurence to a campaign using the variables -> line, product and start date. (Pulling data from table 2 into table 1)
or
- Relate the campaign to multiple occurrences and sum the duration value given in table 1, using the variables -> line, product and the occurrence date, that should be recognized as between start and end date of the campaign (Pulling data from table 1 to table 2)
I have line and product on both tables, on table 1 I have the occurence date and duration; and on table 2 I have the start and end of the campaign.
Don't know if I made my problem clear or If any other information could help.- Ashish_MathurSuper User
Hi,
Share some data and show the expected result.
- ojferreiraFrequent Visitor
Here are some examples of the tables, can't provide exactly the data, but these examples are similars.
I expect to insert the campaign code (some kind of identifier as the example bellow) in a new column on table 1, this way I can then add the durations to the campaigns. And even do more connections after.
ORCreate a new column on table 2 already adding the duration of occurrences from table 1 of that campaign.
Dates in the format - dd/mm/yy hh:mm
Table 1 of occurrences:Line Date Product Duration (Min) Campaign code 11 4/3/22 17:05 4945 5 "some kind of identifier" 11 4/3/22 18:30 4945 2 "ex: 11-4945-03/03/2022 06:00" 12 4/3/22 18:30 567244 3 ? 11 4/3/22 19:00 4945 5 ? 13 4/3/22 19:10 532277 10 ? 11 5/3/22 6:02 5051 7 ? 13 5/3/22 6:05 532277 2 ? Table 2 of campaigns:
Line Product Start date End date Sum of duration 11 4945 24/2/22 9:00 5/3/22 6:00 ? 12 567244 26/2/22 8:00 15/3/22 6:00 ? 13 532277 26/2/22 8:00 6/3/22 9:00 ? 11 5051 5/3/22 6:00 7/3/22 6:00 ?
You can see in the example a campaign change, but more complex things could happen, products being made ate different lines, even at the same time. This is why I think that a identifier with the combination of #LINE, #product and #startdate will be used...I hope this make my problem clearer, it's my first time posting here.
Thanks for your time and help!