Forum Discussion

rdc_green's avatar
rdc_green
Frequent Visitor
4 years ago
Solved

Multiply 2 different columns from 2 tables using datetime as a lookup. The tables cannot be RELATED

Hi,

 

I'm trying to multiply kWh x CO2 based on the timestamp. I have looked through various other solutions, but most of them reference the RELATED function, which doesn't seem to work for me. The two tables look like this:

 

table1

DatetimeCO2
14/03/2022 00:3010
14/03/2022 01:0012

 

table2

reg_datekWh
14/03/2022 00:302
14/03/2022 01:004

 

The result should be the following:

 

DateTotal
14/03/2022 00:3020
14/03/2022 01:0048
Total68

 

I have tried a number of options including:

 

sum(table1[CO2]) + RELATED(table2[kWh])

Sumx (table1, table1[CO2]) + sumx(table2,table2[kWh])

Calculate(SUM(table1[CO2])*SUM(table2[kWh]), FILTER(table1[datetime])

 

For some reason I cannot have a relationship between the two tables (they are both connected to a calendar table - although this doesn't go down to time detail). When I try and connect directly using the datetime column it still doesn't think the tables are RELATED.

 

Thank you

Richard

 

  • If you cannot create a physical relationship between tables then use TREATAS function connecting both the tables and calculate a measure.

     

    Regards

    DI

2 Replies

  • If you cannot create a physical relationship between tables then use TREATAS function connecting both the tables and calculate a measure.

     

    Regards

    DI

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi rdc_green ,

     

    Has your problem been solved? If it is solved, please mark a reply which is helpful to you.

     

    If the problem is still not resolved, please try the following measures:

     

    Measure = 
    SUM ( table1[CO2] )
        * CALCULATE (
            SUM ( table2[kWh] ),
            KEEPFILTERS ( table2[reg_date] = MAX ( table1[Datetime] ) )
        )
    TotalValue = 
    SUMX ( VALUES ( table1[Datetime] ), [Measure] )

     

    Best Regards,
    Winniz