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

Generate an endDateTime based on createDateTime

Hi all,

 

I have a relation that contains statuses of a process. I'm only given a createDateTime and need to make some visualization that counts the statuses that ended today.

 

My data looks like this:

JoepBI_0-1614861582202.png

 

The assumption is that, if the column IsCurrentStatus is NOT equal to 0, the next createDateTime should become the endDateTime for that row. And this needs to be done for each ProcessId individually.

 

Note: I've shown the createDateTimes sorted per processId in ascending order to easily demonstrate the problem, but this is not a given in my dataset.

 

Already a huge thanks in advance for the hero that can solve this 🙂

 

Best, Joep

 

 

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your needs, I did the following test, the created measures are grouped according to Processid, and satisfy if the column IsCurrentStatus is NOT equal to 0, the next createDateTime should become the endDateTime for that row. Refer to the screenshot below:

endDateTime = 
VAR cur_index =
    MIN ( 'Table'[Index] ) + 1
VAR pre_index =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[processID] = MAX ( 'Table'[processID] )
                && 'Table'[Index] <= cur_index
        )
    )
RETURN
    IF (
        MAX ( 'Table'[lsCurrentStatus] ) = 1,
        BLANK (),
        CALCULATE (
            MIN ( 'Table'[createDateTime] ),
            FILTER (
                ALL ( 'Table' ),
                MAX ( 'Table'[processID] ) = 'Table'[processID]
                    && 'Table'[Index] = pre_index
            )
        )
    )

v-henryk-mstf_0-1615365370556.png

Here is the sample pbix file.

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.

 

Best Regards,
Henry

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

5 REPLIES 5
v-henryk-mstf
Community Support
Community Support

Hi @Anonymous ,

 

According to your needs, I did the following test, the created measures are grouped according to Processid, and satisfy if the column IsCurrentStatus is NOT equal to 0, the next createDateTime should become the endDateTime for that row. Refer to the screenshot below:

endDateTime = 
VAR cur_index =
    MIN ( 'Table'[Index] ) + 1
VAR pre_index =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[processID] = MAX ( 'Table'[processID] )
                && 'Table'[Index] <= cur_index
        )
    )
RETURN
    IF (
        MAX ( 'Table'[lsCurrentStatus] ) = 1,
        BLANK (),
        CALCULATE (
            MIN ( 'Table'[createDateTime] ),
            FILTER (
                ALL ( 'Table' ),
                MAX ( 'Table'[processID] ) = 'Table'[processID]
                    && 'Table'[Index] = pre_index
            )
        )
    )

v-henryk-mstf_0-1615365370556.png

Here is the sample pbix file.

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.

 

Best Regards,
Henry

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Create a new column for end time

new column =
var _1 = mix(filter(Table, [processId] = earlier([processId]) && [statusId]> earlier([statusId])),[statusId])
return
if([statusId]<> 0 , _1, blank())

Anonymous
Not applicable

Thanks for your quick and helpful reply @amitchandak! What does the mix-function do? My PowerBI query editor returns "Cannot find name 'mix'. 'mix' is not a function.". Googling for the mix-function didn't return any helpful results either.. 

 

Best,

Joep

@Anonymous , Sorry, typo mistake (MinX)

 

new column =
var _1 = minx(filter(Table, [processId] = earlier([processId]) && [statusId]> earlier([statusId])),[statusId])
return
if([statusId]<> 0 , _1, blank())

Anonymous
Not applicable

Thanks for your fix! Unfortunately, this does not result in the desired column (WANTED: endDateTime) as shown in the picture. Any solutions how to get to that desired result?

 

Best, Joep

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.