Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate Sum between two TIMES (Not Dates)

Hi All,

I have an issue where I'm trying to find the SUM energy between two times, a departing time and an arrival time. However, when I try to sum using a filter I get nothing. I know the data is there because I can manually find it in the table.
For Context:
Table 1 has every minute marked, along with how much energy was used in that minute

Table 2 has a departing time and arrival time that I'd like to calculate between

The calculation I have tried:

EnergyUse =
CALCULATE(
SUM(Table1[Energy]),
FILTER(Table1, Table1[Time]>='Table2'[dep]),
FILTER( Table1, Table1[Time]<='Table2'[arr])
)
I have also tried this but with '&&' instead of two filters, but that didn't work either. 
Please Help!
1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Looks like you are creating a calculated column, try like this:

EnergyUse =
CALCULATE (
    SUM ( 'Table1'[Energy] ),
    FILTER (
        ALL ( Table1 ),
        'Table1'[Time] >= MIN ( 'Table2'[dep] )
            && 'Table1'[Time] <= MIN ( 'Table2'[arr] )
    )
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

Looks like you are creating a calculated column, try like this:

EnergyUse =
CALCULATE (
    SUM ( 'Table1'[Energy] ),
    FILTER (
        ALL ( Table1 ),
        'Table1'[Time] >= MIN ( 'Table2'[dep] )
            && 'Table1'[Time] <= MIN ( 'Table2'[arr] )
    )
)

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Time greater than or equal to departure 

and

Time lesser than or equal to arrival

 

This doesnt make sense , shouldnt the filter be

FILTER(Table1, Table1[Time]<='Table2'[dep]),
FILTER( Table1, Table1[Time]>='Table2'[arr])
Anonymous
Not applicable

Greater than or equal to is >= no?
So it's >= depart time and <= arrive time to get the times in between?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.