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
SBAV01
Frequent Visitor

Measure to format next datetime from NOW() in list of datetimes in a table visual

Hello

 

I am making a report which shows fulfillment of events to various departments. The main visual is a table which lists the events in DateTime order with a DateTime formatted field. There are filters and slicers for reletive date and department. The report is using DirectQuery. The report will function as a wallboard autorefreshing through the day and I want to indicate clearly which is the next event in the filtered list so at a glance they can see if they are ahead or behind on their fulfillment. 

What I have in mind is including a mesaure which only returns a result for the next event visible in the list and use that measure with conditional formatting on the row which is the next event.

Currently my attempt at a measure looks like this:

NextEvent =
VAR CurrentDateTime = NOW()  
VAR NextEventDateTime = MIN('Transport'[DateTime])  
RETURN
    IF(
        CurrentDateTime < NextEventDateTime,  
        "Next Event"
        BLANK()  
    )

But I think my issue is that it is evaluating the Variable against each line of the table so the result is that all future events get the "Next Event" tag.
Trying to do some reading and I think I need to use some combination of Calculate / AllSelected / Filter within the variable.

Sample table

EventIDDayDateTimeDepartmentOutstandingFulfilment%
101Tue21/03/2023 00:00X0100.00%
139Tue21/03/2023 07:30X18990.17%
145Tue21/03/2023 07:30X0100.00%
415Tue21/03/2023 08:00X0100.00%
394Tue21/03/2023 09:01X4095.88%
378Tue21/03/2023 17:00X17048.33%
400Wed22/03/2023 09:00X0100.00%
284Wed22/03/2023 09:01X74860.65%
163Wed22/03/2023 09:01X3289.89%
459Wed22/03/2023 09:01X76234.20%



Anyone help point me in the right direction?
Many Thanks

7 REPLIES 7
lbendlin
Super User
Super User

Define "next".  For example which event is "next"  after event 400 ?

After 400 would be 284 & 163 & 459. I don't mind how the measure would treat rows with the same DateTime - The simpler the better would help me understand but if I had a preference it would only return for the the first matching number. In this case 284.
Thank you

then slap an index column onto your raw data (assuming it is sorted by date) and grab the row that has the next index.  Or use the OFFSET function.  

 

Do you want this in DAX or in Power Query?  calculated column or measure?

A DAX Measure would be most suitable I think as it is a direct query and the pages are filtered for different departments so it needs to figure out the 'next' event per filtered table.
Is the Index column the solution for where the 'next' event has matching DateTimes with others?
Thanks

yes, it's to break the ties.  Alternatives would be to use TOPN(1,xxx) but these may be more costly.  Doesn't matter if you want it as a measure - there the index won't help too much.

Thanks - How do I actually go about grabbing the next index or datetime when displaying a range of events in a table?

Kind Regards
Stephen

Grab the "current" index, then find the smallest index that is bigger than that, then the date for that index.

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.