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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Joel_sony
Frequent Visitor

How to find the number of days between rows Saturday

Hey guys! Can someone help me out how to create a new column which calculates the difference of days between each row similiar to the daydifference in this table?Screenshot 2024-11-12 161843.png

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Joel_sony ,

 

You can refer to the following steps.
1. Go to power query editor and create new index column.

vkaiyuemsft_0-1731478720995.png

 

2. In power bi desktop, create a new calculated column and write the following expression.

DayDifference = 
    VAR CurrentResponseID = 'Table'[response_id]
    VAR CurrentCreatedAt = 'Table'[created_at]
    VAR PreviousCreatedAt = 
        CALCULATE(
            MAX('Table'[created_at]),
            FILTER(
                'Table',
                'Table'[response_id] = CurrentResponseID &&
                'Table'[id] < EARLIER('Table'[id])
            )
        )
    RETURN
        IF(
            ISBLANK(PreviousCreatedAt),
            0,
            ABS(DATEDIFF(PreviousCreatedAt, CurrentCreatedAt, DAY))
        )

vkaiyuemsft_1-1731478743773.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

View solution in original post

Hello @Joel_sony ,

 

Here is the dax for your requirement .

I have given 0 if next date in sequence is not available in case of change in response_id or end of data. Please modify as per need 

 

VAR CurrentDate = Tab_Response[Created_At]
VAR NextDate =
    CALCULATE(
        MIN(Tab_Response[Created_At]),
        FILTER(
            Tab_Response,
            Tab_Response[Response_id] = EARLIER(Tab_Response[Response_id]) &&
            (Tab_Response[Created_At] > CurrentDate ||
            (Tab_Response[Created_At] = CurrentDate && Tab_Response[ID] > EARLIER(Tab_Response[ID])))
        )
    )
RETURN
    IF(
        ISBLANK(NextDate),
        0,
        IF(
            DATEDIFF(CurrentDate, NextDate, DAY) = 0,
            0,
            DATEDIFF(CurrentDate, NextDate, DAY)
        )
    )
 
divyed_0-1731486109988.png

 

Did I answer your query ? Mark this as solution if this helps . Appreciate your Kudos.

 

Cheers.

Neeraj Kumar

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Joel_sony ,

 

You can refer to the following steps.
1. Go to power query editor and create new index column.

vkaiyuemsft_0-1731478720995.png

 

2. In power bi desktop, create a new calculated column and write the following expression.

DayDifference = 
    VAR CurrentResponseID = 'Table'[response_id]
    VAR CurrentCreatedAt = 'Table'[created_at]
    VAR PreviousCreatedAt = 
        CALCULATE(
            MAX('Table'[created_at]),
            FILTER(
                'Table',
                'Table'[response_id] = CurrentResponseID &&
                'Table'[id] < EARLIER('Table'[id])
            )
        )
    RETURN
        IF(
            ISBLANK(PreviousCreatedAt),
            0,
            ABS(DATEDIFF(PreviousCreatedAt, CurrentCreatedAt, DAY))
        )

vkaiyuemsft_1-1731478743773.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

divyed
Super User
Super User

Hello @Joel_sony ,

 

Appreciate if you share logic behind the calculation. How are you finding daydifference ? 

 

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

This works based on this equation daydifference(created) = daydifference(created)-daydifference(started),
daydifference(started)=daydifference(started)-daydifference(submitted) and continue on until new response_id reaches, When new response_id reaches this process should restart. All values in positive only. 

Hello @Joel_sony ,

 

Here is the dax for your requirement .

I have given 0 if next date in sequence is not available in case of change in response_id or end of data. Please modify as per need 

 

VAR CurrentDate = Tab_Response[Created_At]
VAR NextDate =
    CALCULATE(
        MIN(Tab_Response[Created_At]),
        FILTER(
            Tab_Response,
            Tab_Response[Response_id] = EARLIER(Tab_Response[Response_id]) &&
            (Tab_Response[Created_At] > CurrentDate ||
            (Tab_Response[Created_At] = CurrentDate && Tab_Response[ID] > EARLIER(Tab_Response[ID])))
        )
    )
RETURN
    IF(
        ISBLANK(NextDate),
        0,
        IF(
            DATEDIFF(CurrentDate, NextDate, DAY) = 0,
            0,
            DATEDIFF(CurrentDate, NextDate, DAY)
        )
    )
 
divyed_0-1731486109988.png

 

Did I answer your query ? Mark this as solution if this helps . Appreciate your Kudos.

 

Cheers.

Neeraj Kumar

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
Angith_Nair
Continued Contributor
Continued Contributor

Hi @Joel_sony 

Please elaborate and add what the new column should look like.

This works based on this equation daydifference(created) = daydifference(created)-daydifference(started)
daydifference(started)=daydifference(started)-daydifference(submitted) and continue on until new response_id reaches, When new response_id reaches this process should restart. All values in positive only.  The same column(daydifference) as in the image

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.