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

Calculating difference in minutes based on variables

Hi,

 

I have an issue with finding the exact date difference between two transactions. But the difference must calculate the date difference between transactions of the same person AND put a 0 where there were 2 transactions at the exact same moment.

 

image.png

 

So far, I have 2 solutions, each solves one part of the problem.

Number 1  - put a 0 where there are 2 transactions at the same time:

Column 2 = 
VAR ind = 'Sample'[Index] - 1
VAR pre =
    CALCULATE (
        MAX ( 'Sample'[Date and time of visit] );
        FILTER ( 'Sample'; 'Sample'[Index] = ind )
    )
RETURN
    DATEDIFF ( pre; 'Sample'[Date and time of visit]; MINUTE )

image.png

 

Number 2 - calculate the time difference in transactions of the same person:

Column 3 = DATEDIFF(CALCULATE(MIN('Sample'[Date and time of visit]);FILTER('Sample';EARLIER('Sample'[Name])='Sample'[Name]));'Sample'[Date and time of visit];MINUTE)

image.png

 

So hopefully, a combination of these two is possible - calculate the difference in time for transactions of a particular person and put a zero where that person had 2 transactions at the same moment.

 

I hope my explanation is clear.

 

Regards

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @Yamabushi ,

 

You can use following calculate column formula to achieve your requirement:

Diff =
VAR _pIndex =
    CALCULATE (
        MAX ( Table[Index] ),
        FILTER (
            ALL ( Table ),
            [Index] < EARLIER ( Table[Index] )
                && [Name] = EARLIER ( Table[Name] )
        )
    )
VAR _pVisit =
    LOOKUPVALUE ( Table[Date and time of visit], Table[Index], _pIndex )
RETURN
    IF (
        _pVisit <> BLANK (),
        DATEDIFF ( _pVisit, Table[Date and time of visit], MINUTE ),
        0
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

HI @Yamabushi ,

 

You can use following calculate column formula to achieve your requirement:

Diff =
VAR _pIndex =
    CALCULATE (
        MAX ( Table[Index] ),
        FILTER (
            ALL ( Table ),
            [Index] < EARLIER ( Table[Index] )
                && [Name] = EARLIER ( Table[Name] )
        )
    )
VAR _pVisit =
    LOOKUPVALUE ( Table[Date and time of visit], Table[Index], _pIndex )
RETURN
    IF (
        _pVisit <> BLANK (),
        DATEDIFF ( _pVisit, Table[Date and time of visit], MINUTE ),
        0
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi,

This was exactly what I needed, thanks!

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.