Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
eliasayyy
Memorable Member
Memorable Member

find datediff between date and direct next date with user filter

hello everyone, i have a table, 
"transaction table"

i made a table visual that has transaction date and nb  of transactions made

as a filter slicer, i have userID

here is an example

eliasayyy_0-1705415663981.png


i need to add a new measure that will calculate the dattdif between each row of date

so for first row 0 becasue there is no previous date

then from first row to second row

there is 30 days almost so 30 days

then between second row and third row there is a diff of 1 day

..

after that i need to find the average so i can know how much this customer returns on average

So if we only take the first 2 calcultaions

30 + 1 = 31/2 = 15 days average



1 ACCEPTED SOLUTION
Dangar332
Super User
Super User

hi, @eliasayyy 

try below

Measure 16 = 
var a  = ADDCOLUMNS(
    ALL('transaction table'[transaction date],'transaction table'[transaction],'transaction table'[userid]),
    "datediff",
    var a = 'transaction table'[transaction date]
    var b =
         MINX(
           FILTER(
              'transaction table',
              'transaction table'[userid]=EARLIER('transaction table'[userid]) &&
              'transaction table'[transaction date]>a
            ),
              'transaction table'[transaction date]
        )
    var c= IF(b=BLANK(),a,b)
    RETURN
    DATEDIFF('transaction table'[transaction date],c,DAY)
)
RETURN
AVERAGEX(FILTER(a,'transaction table'[transaction date]<=MAX('transaction table'[transaction date])),[datediff])

 

Dangar332_1-1705426012813.png

 

View solution in original post

1 REPLY 1
Dangar332
Super User
Super User

hi, @eliasayyy 

try below

Measure 16 = 
var a  = ADDCOLUMNS(
    ALL('transaction table'[transaction date],'transaction table'[transaction],'transaction table'[userid]),
    "datediff",
    var a = 'transaction table'[transaction date]
    var b =
         MINX(
           FILTER(
              'transaction table',
              'transaction table'[userid]=EARLIER('transaction table'[userid]) &&
              'transaction table'[transaction date]>a
            ),
              'transaction table'[transaction date]
        )
    var c= IF(b=BLANK(),a,b)
    RETURN
    DATEDIFF('transaction table'[transaction date],c,DAY)
)
RETURN
AVERAGEX(FILTER(a,'transaction table'[transaction date]<=MAX('transaction table'[transaction date])),[datediff])

 

Dangar332_1-1705426012813.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.