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
DRing
Helper V
Helper V

DAX for records between previous day 9:00 PM and current day 6:00 AM?

I have data like below where calls are coming into a call center. The businuess users want a report they can check daily that shows them calls that came in "after hours", between the time of 9:00 PM of the previous day and 6:00 PM of the current day.

 

For example, on the morning of 1/31/2024, the report would show calls between 1/30/2024 9:00 PM and 1/31/2024 6:00 AM.

What DAX will allow me to identify calls in this way?

 

CALL_IDCALL_TIMEPHONE_NUMBERCALL_DURATION_SECONDS
11/30/24 12:08 PM(xxx) xxx-xxxx13
22/1/24 1:18 PM(xxx) xxx-xxxx10
31/31/24 2:54 PM(xxx) xxx-xxxx44
41/31/24 2:10 PM(xxx) xxx-xxxx19
52/1/24 2:15 PM(xxx) xxx-xxxx42
61/31/24 11:47 AM(xxx) xxx-xxxx60
72/1/24 10:39 AM(xxx) xxx-xxxx32
81/29/24 10:53 AM(xxx) xxx-xxxx5
91/29/24 11:12 AM(xxx) xxx-xxxx17
102/1/24 11:19 AM(xxx) xxx-xxxx54
111/30/24 1:28 PM(xxx) xxx-xxxx18
122/1/24 10:50 AM(xxx) xxx-xxxx19
132/1/24 1:48 PM(xxx) xxx-xxxx0
141/30/24 1:13 PM(xxx) xxx-xxxx53
151/31/24 2:25 PM(xxx) xxx-xxxx38
161/29/24 10:25 AM(xxx) xxx-xxxx39
171/29/24 11:43 AM(xxx) xxx-xxxx26
181/31/24 12:59 PM(xxx) xxx-xxxx7
191/29/24 1:51 PM(xxx) xxx-xxxx48
201/30/24 11:27 AM(xxx) xxx-xxxx29
212/1/24 1:24 PM(xxx) xxx-xxxx51
221/30/24 12:14 PM(xxx) xxx-xxxx2
231/29/24 11:37 AM(xxx) xxx-xxxx37
241/31/24 12:14 PM(xxx) xxx-xxxx57
251/29/24 1:37 PM(xxx) xxx-xxxx50
262/1/24 2:09 PM(xxx) xxx-xxxx57
272/1/24 1:13 PM(xxx) xxx-xxxx4
281/29/24 2:34 PM(xxx) xxx-xxxx56
291/29/24 10:05 AM(xxx) xxx-xxxx31
301/30/24 12:21 PM(xxx) xxx-xxxx8
312/1/24 2:31 PM(xxx) xxx-xxxx9
2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@DRing Try a Complex Selector like this: The Complex Selector - Microsoft Fabric Community

Selection Measure = 
    VAR __CallTime = MAX('Table2'[CALL_TIME])
    VAR __Today = TODAY()
    VAR __Yesterday = __Today - 1
    VAR __Start = __Yesterday + TIME(17, 0, 0)
    VAR __End = __Today + TIME(6, 0, 0)
    VAR __Result = IF( __CallTime >= __Start && __CallTime <= __End, 1, 0)
RETURN
    __Result

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-junyant-msft
Community Support
Community Support

Hi @DRing ,

@Greg_Deckler Good answer!,
And you can also create a slicer, please try this way:
Here is my sample data:

vjunyantmsft_0-1706843854228.png

And I create a new table for slicer:

vjunyantmsft_1-1706843888610.png

There is no relationship between the two tables:

vjunyantmsft_2-1706843930753.png

I use this DAX to create a measure:

CallsCount = 
VAR SELECTED_TIME = SELECTEDVALUE('Table 2'[Date])
VAR StartTime = (SELECTED_TIME - 1) + TIME(21, 0, 0)
VAR EndTime = SELECTED_TIME + TIME(6, 0, 0)
RETURN
IF(
    ISFILTERED('Table 2'[Date]),
    IF(
        MAX('Table'[CALL_TIME]) >= StartTime && MAX('Table'[CALL_TIME]) <= EndTime,
        1,
        0
    ),
    1
)

Put this measure into the "Filters on this visual":

vjunyantmsft_3-1706844045090.png

The final output is below:

vjunyantmsft_4-1706844064935.png
Best Regards,
Dino Tao
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

2 REPLIES 2
v-junyant-msft
Community Support
Community Support

Hi @DRing ,

@Greg_Deckler Good answer!,
And you can also create a slicer, please try this way:
Here is my sample data:

vjunyantmsft_0-1706843854228.png

And I create a new table for slicer:

vjunyantmsft_1-1706843888610.png

There is no relationship between the two tables:

vjunyantmsft_2-1706843930753.png

I use this DAX to create a measure:

CallsCount = 
VAR SELECTED_TIME = SELECTEDVALUE('Table 2'[Date])
VAR StartTime = (SELECTED_TIME - 1) + TIME(21, 0, 0)
VAR EndTime = SELECTED_TIME + TIME(6, 0, 0)
RETURN
IF(
    ISFILTERED('Table 2'[Date]),
    IF(
        MAX('Table'[CALL_TIME]) >= StartTime && MAX('Table'[CALL_TIME]) <= EndTime,
        1,
        0
    ),
    1
)

Put this measure into the "Filters on this visual":

vjunyantmsft_3-1706844045090.png

The final output is below:

vjunyantmsft_4-1706844064935.png
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Super User
Super User

@DRing Try a Complex Selector like this: The Complex Selector - Microsoft Fabric Community

Selection Measure = 
    VAR __CallTime = MAX('Table2'[CALL_TIME])
    VAR __Today = TODAY()
    VAR __Yesterday = __Today - 1
    VAR __Start = __Yesterday + TIME(17, 0, 0)
    VAR __End = __Today + TIME(6, 0, 0)
    VAR __Result = IF( __CallTime >= __Start && __CallTime <= __End, 1, 0)
RETURN
    __Result

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.