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
ShaneL79
Helper I
Helper I

Showing Sum of Data Between Two Dates

Hello Everyone,

 

I have a very large weekly report (created by someone else). I am having trouble with one function. 

 

One chart shows incorrect values because it only accounts for the start date, not the end date. This means that if an event crosses into a second (or more) week, it only records the time in the present week.

 

I have went through the data, thanks to a user of this site, and separated each event out by daily totals into a new table. Now my data looks like this:

DATA TABLE:

EVENT IDSTART DATEEND DATEDURATION
0111/26/2022 2:00:00 PM11/26/2022 11:59:59 PM9.999
0111/27/2022 12:00:00 AM11/27/2022 8:00:00 AM8
0211/27/2022 4:00:00 PM11/27/2022 5:00:00 PM1

 

There is also a table for "Weeks" that is used by the drop down splicer. It has the following fields:

 

WEEK TABLE:

START OF WEEKEND OF WEEKDROPDOWN REPORT NAME
Sunday, November 27, 2022Saturday, December 3, 20222022-12-03Nov 27, 2022 - Dec 3, 2022
Sunday, November 20, 2022Saturday, November 26, 20222022-11-27Nov 20, 2022 - Nov 26, 2022

 

Every chart in this large report uses that table for dropdown list. There is another data table that has been getting used that looks like this:

 

EVENT TABLE:

EVENT IDRECEIVED TIMESTART TIMEEND TIMEDURATION
0111/26/2022 2:00:00 PM11/26/2022 2:00:00 PM11/27/2022 8:00:00 AM18
0211/27/2022 4:00:00 PM11/27/2022 4:00:00 PM11/27/2022 5:00:00 PM1

 

This is the original table where an entire event is on a single row. In contrast, the DATA TABLE above splits events into multiple rows when they go across multiple days.

 

Not all events have a "START TIME" or "END TIME" so those can be null in both EVENT and DATA tables. To try to clarify that, received time is the time an alert rings in. START TIME and END TIME are only used when workers are sent to repair the issue. It is "null" otherwise.

 

What I Want To Do:

 

I want to create a chart that looks at the DATA TABLE and only includes values with a START DATE between the WEEK TABLE START/END dates. Using Event ID #1, Only row #1 (Duration = 9.999) of the DATA TABLE would show when week Nov 20, 2022 - Nov 26, 2022 was selected, and row 2 and event #2 would show when week Nov 27, 2022 - Dec 3, 2022 was selected. 

 

This seems like it is something easy, but I cannot get it so I assume multiple connections between the tables are involved and likely need to either trace it down OR rebuild the chart using completely different data (aside from the drop down which cannot be changed).

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@ShaneL79,

 

Try this measure:

 

Duration = 
VAR vWeekStart =
    SELECTEDVALUE ( WeekTable[START OF WEEK] )
VAR vWeekEnd =
    SELECTEDVALUE ( WeekTable[END OF WEEK] )
VAR vResult =
    CALCULATE (
        SUM ( 'DataTable'[DURATION] ),
        INT ( 'DataTable'[START DATE] ) >= vWeekStart, // use INT to remove time portion
        INT ( 'DataTable'[START DATE] ) <= vWeekEnd
    )
RETURN
    vResult

 

DataInsights_0-1674065304587.png

 

No relationship exists between WeekTable and DataTable.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
DataInsights
Super User
Super User

@ShaneL79,

 

Try this measure:

 

Duration = 
VAR vWeekStart =
    SELECTEDVALUE ( WeekTable[START OF WEEK] )
VAR vWeekEnd =
    SELECTEDVALUE ( WeekTable[END OF WEEK] )
VAR vResult =
    CALCULATE (
        SUM ( 'DataTable'[DURATION] ),
        INT ( 'DataTable'[START DATE] ) >= vWeekStart, // use INT to remove time portion
        INT ( 'DataTable'[START DATE] ) <= vWeekEnd
    )
RETURN
    vResult

 

DataInsights_0-1674065304587.png

 

No relationship exists between WeekTable and DataTable.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Worked perfectly. Thank you very much!

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.