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

Time

Hi 

I have used this code to determine the time difference between rows as a messure. 

 

This looks at each row of data. 

 

Time Difference Measure13 =
VAR NextRow =
CALCULATE (
MIN ( FAC[Start Date/Time] ),
FILTER (
ALL ( FAC ),
FAC[Start Date/Time] > SELECTEDVALUE ( FAC[Start Date/Time] )
)
)
RETURN
IF (
SELECTEDVALUE ( FAC[Consist] ) = 0,
DATEDIFF ( SELECTEDVALUE ( FAC[Start Date/Time] ), NextRow, SECOND )
)
 
 

How would i determine the difference when using a slicer? The index is showing what lines the data is on just for me to understand what the messure was doing.

 

If i select consist using a slicer i would like the messure to determin the time difference.

 

pic.PNG

 

Any help would be appricated - i have spent hours trying to find a solution.

1 ACCEPTED SOLUTION

Hello @RichardT_78 ,

You can update your measurement as below screenshot shown, please find more details in the attachment:

Time Difference = 
VAR _nexindex =
    CALCULATE (
        MIN ( 'FAC'[Index] ),
        FILTER (
            ALLEXCEPT ( 'FAC', 'FAC'[Consist] ),
            'FAC'[Index] > MAX ( 'FAC'[Index] )
        )
    )
VAR _nexttime =
    CALCULATE (
        MAX ( 'FAC'[Start Date/Time] ),
        FILTER ( ALLEXCEPT ( 'FAC', 'FAC'[Consist] ), 'FAC'[Index] = _nexindex )
    )
RETURN
    DATEDIFF ( SELECTEDVALUE ( 'FAC'[Start Date/Time] ), _nexttime, SECOND ) + 0

Time.JPG

Best regards

Community Support Team _ Rena
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
eleverson
New Member

Hello,

 

I am using a crime dataset and trying to put it in a star schema. However, when I merge the dimension table with a fact table it causes the fact table to add additional rows. This dataset has three different date columns and three different time columns. I have tried so many different ways and got the same results. Here is a screenshot of the data model. And the file to the original dataset.

 

eleverson_0-1640585457641.pnghttps://data.brla.gov/Public-Safety/Baton-Rouge-Crime-Incidents/pbin-pcm7/data 

 

RichardT_78
Helper I
Helper I

Thank you

RichardT_78
Helper I
Helper I

consist.PNG

consist 104.PNG

ConsistStart Date/Time
37743601/12/2020 13:08:51
37743601/12/2020 13:08:50
37715301/12/2020 13:06:32
37715301/12/2020 13:06:30
37740801/12/2020 13:04:51
37743601/12/2020 13:04:40
37743601/12/2020 13:04:39
37714001/12/2020 13:02:14
37714001/12/2020 13:02:12
37743601/12/2020 13:01:00
37743601/12/2020 13:00:59
37742401/12/2020 12:59:54
37742401/12/2020 12:59:51
37744701/12/2020 12:59:40
37710401/12/2020 12:59:36

377436 would be a good test as its spread over the table  

So are for example 100 consist codes, which all have a time stamp for each particular event.

When I use a slicer and select 377104 for example, it displays all events chronologically, but the messure fails. 

As you can see the messure works fine when you dont focus on a consist, but when i select a consist its rows are not consecutive.

 

Hope this helps , much appricated 

Hello @RichardT_78 ,

You can update your measurement as below screenshot shown, please find more details in the attachment:

Time Difference = 
VAR _nexindex =
    CALCULATE (
        MIN ( 'FAC'[Index] ),
        FILTER (
            ALLEXCEPT ( 'FAC', 'FAC'[Consist] ),
            'FAC'[Index] > MAX ( 'FAC'[Index] )
        )
    )
VAR _nexttime =
    CALCULATE (
        MAX ( 'FAC'[Start Date/Time] ),
        FILTER ( ALLEXCEPT ( 'FAC', 'FAC'[Consist] ), 'FAC'[Index] = _nexindex )
    )
RETURN
    DATEDIFF ( SELECTEDVALUE ( 'FAC'[Start Date/Time] ), _nexttime, SECOND ) + 0

Time.JPG

Best regards

Community Support Team _ Rena
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

@RichardT_78 ,The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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.