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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Tommyvhod
Helper II
Helper II

Differentiate operations

Hello all

 

I have a formula which calculates the days between two operations:

 

Aging = var _time =
    MAX(Data[Datum trans])
        VAR _maxLastTime  =
        CALCULATE(MAX(Data[Datum trans]),
        FILTER(ALLEXCEPT(Data, Data[ID]), Data[Datum trans] < _time)
        )
    VAR _datedif =
    DATEDIFF(_maxLastTime,_time,DAY)
    Return
    IF(_datedif >0,_datedif,0)
 
The problem here is that if I have the same date on the last 4 operations and x day before those all the 4 last operations shows x day difference.
I am wondering how could I add another line differenciating the number of the operation ( its always ascending - eg. operation 1, 2 , 5 , 10, 20, etc)
 
Thank you
1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Tommyvhod ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1671167709217.png

Please try:

add an index column:

vjianbolimsft_1-1671167756528.png

Then apply the measure:

Aging = 
var _time =
    MAX(Data[Datum trans])
var _index = MAX('Data'[Index])
        VAR _maxLastTime  =
        CALCULATE(MAX(Data[Datum trans]),
        FILTER(ALLEXCEPT(Data, Data[ID]), [Index]=_index-1)
        )
    VAR _datedif =
    DATEDIFF(_maxLastTime,_time,DAY)
    Return
    IF(_datedif >0,_datedif,0)

Final output:

vjianbolimsft_2-1671167963880.png

Best Regards,

Jianbo Li

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

2 REPLIES 2
Tommyvhod
Helper II
Helper II

Thank you. Yes the index column was a good Idea. What I also changed is the

IF(_datedif >0,_datedif,0)

To _datedif, Blank()) so the visual wont show unecessary columns

v-jianboli-msft
Community Support
Community Support

Hi @Tommyvhod ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_0-1671167709217.png

Please try:

add an index column:

vjianbolimsft_1-1671167756528.png

Then apply the measure:

Aging = 
var _time =
    MAX(Data[Datum trans])
var _index = MAX('Data'[Index])
        VAR _maxLastTime  =
        CALCULATE(MAX(Data[Datum trans]),
        FILTER(ALLEXCEPT(Data, Data[ID]), [Index]=_index-1)
        )
    VAR _datedif =
    DATEDIFF(_maxLastTime,_time,DAY)
    Return
    IF(_datedif >0,_datedif,0)

Final output:

vjianbolimsft_2-1671167963880.png

Best Regards,

Jianbo Li

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

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.