Forum Discussion

Heinet's avatar
Heinet
Frequent Visitor
3 years ago
Solved

Sum of data between two dates in another table

Hi

 

I have 2 tables, simplified like this:

 

Table 1:

 

IncidentDatapointFrom timeTo time
1A01.01.2022 12:0001.01.2022 14:00
2A01.01.2022 22:0001.02.2022.03:00
3B02.02.2022 03:0002.02.2022 05:00
4C03.02.2022 15:0004.02.2022 13:00

 

And Table 2

 

From timeTo TimeAmountDatapoint
01.01.2022 01:00 01.01.2022 02:0040A
 01.01.2022 02:0001.01.2022 03:0036A
01.01.2022 03:0001.01.2022 04:0012A
01.01.2022 04:0001.01.2022 05:0016A

 

And the table continues with amount for every 1h intervall for all datapoints.

 

Then my goal is to sum amount for each incident (in the first table) filters that sums amount with filters Table 2 (From time) <= Table 1 (From time), Table 2 (To Time) >= Table 1 (To time) and Table 1 (Datapoint) = Table 2 (Datapoint)

 

I tried with a simple Calculate(sum Table 2 Amount), Filter(Table 2, Table 2 (From time) <= Table 1 (From time) && Table 2 (To Time) >= Table 1 (To time) && Table 1 (Datapoint) = Table 2 (Datapoint)) but that didn't work. Might be some simple solution that I just can't see so would really appriciate the support

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Heinet ,

    Please try to create measure with below dax formula:

    Measure =
    VAR cur_int =
        SELECTEDVALUE ( Table1[Incident] )
    VAR cur_ft =
        SELECTEDVALUE ( Table1[From time] )
    VAR cur_tt =
        SELECTEDVALUE ( Table1[To time] )
    VAR cur_dp =
        SELECTEDVALUE ( Table1[Datapoint] )
    VAR tmp =
        FILTER (
            ALL ( Table2 ),
            Table2[From time] <= cur_ft
                && Table2[To Time] >= cur_tt
                && Table2[Datapoint] = cur_dp
        )
    RETURN
        SUMX ( tmp, [Amount] )
    

    Add a table visual with Table1 fields and above measure

    The measure is empty because there is no data to satisfy the condition.

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Heinet ,

    Please try to create measure with below dax formula:

    Measure =
    VAR cur_int =
        SELECTEDVALUE ( Table1[Incident] )
    VAR cur_ft =
        SELECTEDVALUE ( Table1[From time] )
    VAR cur_tt =
        SELECTEDVALUE ( Table1[To time] )
    VAR cur_dp =
        SELECTEDVALUE ( Table1[Datapoint] )
    VAR tmp =
        FILTER (
            ALL ( Table2 ),
            Table2[From time] <= cur_ft
                && Table2[To Time] >= cur_tt
                && Table2[Datapoint] = cur_dp
        )
    RETURN
        SUMX ( tmp, [Amount] )
    

    Add a table visual with Table1 fields and above measure

    The measure is empty because there is no data to satisfy the condition.

    Please refer the attached .pbix file.

     

    Best regards,
    Community Support Team_ Binbin Yu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.