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
aslam-ansari
Frequent Visitor

Help with DAX calculation: Finding END Date

More equipment is listed in the equipment column, which I filter out to make sense of.

 

Screenshot 2023-05-29 163829.png

 

The result should be like this:

Screenshot 2023-05-29 163841.png

1 ACCEPTED SOLUTION

@aslam-ansari 
My mistake again

End Date =
VAR CurrentDate = 'Table'[Start Date]
VAR CurrentEquipmentDates =
    CALCULATETABLE (
        VALUES ( 'Table'[Start Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Equipment] )
    )
VAR NextDate =
    MINX (
        FILTER ( CurrentEquipmentDates, 'Table'[Start Date] > CurrentDate ),
        'Table'[Start Date]
    )
RETURN
    IF ( NextDate = BLANK (), TODAY (), NextDate - 1 )

View solution in original post

5 REPLIES 5
aslam-ansari
Frequent Visitor

hai @tamerj1 

Getting error.
Screenshot 2023-05-30 094432.png

 

My actual table looks like this. 

aslamansari_0-1685425610566.png

 

In that scenario, take into account time. Some equipment status changes even occur on the same date. The end date in these circumstances should be the same date up to 3:11:06 PM, and thereafter it should be TODAY().

 

aslamansari_2-1685426381997.png

 

 

 

 

@aslam-ansari 
Apologies, That was a typo mistake. I was typing on the phone so I miussed up. Please try

End Date =
VAR CurrentDate = 'Table'[Start Date]
VAR CurrentEquipmentDates =
    CALCULATETABLE (
        VALUES ( 'Table'[Start Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Equipment] )
    )
VAR NextDate =
    MAXX (
        FILTER ( CurrentEquipmentDates, 'Table'[Start Date] > CurrentDate ),
        'Table'[Start Date]
    )
RETURN
    IF ( NextDate = BLANK (), TODAY (), NextDate - 1 )

Thank you for the solution @tamerj1 

Something missing in Dax!
After the first-row same-date return on all dates, the equation still needs to be changed. This only applies to one piece of equipment. Every piece of equipment has this issue.

Screenshot 2023-05-30 113528.png

@aslam-ansari 
My mistake again

End Date =
VAR CurrentDate = 'Table'[Start Date]
VAR CurrentEquipmentDates =
    CALCULATETABLE (
        VALUES ( 'Table'[Start Date] ),
        ALLEXCEPT ( 'Table', 'Table'[Equipment] )
    )
VAR NextDate =
    MINX (
        FILTER ( CurrentEquipmentDates, 'Table'[Start Date] > CurrentDate ),
        'Table'[Start Date]
    )
RETURN
    IF ( NextDate = BLANK (), TODAY (), NextDate - 1 )
tamerj1
Super User
Super User

Hi @aslam-ansari 

please try

End Date =
VAR CurrentDate = 'Table'[Start Date]
VAR CurrentEquipmentDates =
CALCULATETABLE (
VALUES ( 'Table'[Start Date] ),
ALLEXCEPT ( 'Table', 'Table'[Equipment] )
)
VAR NextDate =
MAXX (
FILTER ( CurrentEquipmentDates, CurrentEquipmentDates > CurrentDate ),
CurrentEquipmentDates
)
RETURN
IF ( NextDate = BLANK (), TODAY (), NextDate - 1 )

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.

Top Solution Authors