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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
RobRayborn
Helper IV
Helper IV

difference from previous Friday

I need to calculate the difference between the amount taken on a day and the amount taken on the previous day.  The problem is that on Satruday and Sunday the amount doesn't change, so on Monday my difference ends up being Zero. So I end up with only four days. 
I need to subtract Monday from the previous Friday amount.  
I have a standard Date Table with offsets and "IsWeekday" type columns. 

The blue highlight below shows the amount on prevous Friday. The yellow highlight shows the % amount diff from previous day, or DATEADD, -1, DAY.

Screenshot 2023-03-06 160241.jpg 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

There are some ways to achieve this, and I think it depends on how the business process for Saturday and Sunday is defined. I assume there are blank (not zero) data on Sat and Sun, and one of ways to achieve this is using lastnonblank DAX function.

Jihwan_Kim_1-1678163509273.png

 

 

Jihwan_Kim_0-1678163477431.png

 

Diff %: =
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _lastnonblank =
    CALCULATE (
        LASTNONBLANK ( 'Calendar'[Date], [Value sum:] ),
        FILTER ( ALL ( 'Calendar'[Date] ), 'Calendar'[Date] < _currentdate )
    )
VAR _lastnonblankvalue =
    CALCULATE ( [Value sum:], 'Calendar'[Date] = _lastnonblank )
RETURN
    IF (
        NOT ISBLANK ( [Value sum:] ) && HASONEVALUE ( 'Calendar'[Date] ),
        DIVIDE ( [Value sum:] - _lastnonblankvalue, _lastnonblankvalue )
    )

 



Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



View solution in original post

5 REPLIES 5
RobRayborn
Helper IV
Helper IV

Thank you so much for the assitance!  This worked perfectly.

FreemanZ
Super User
Super User

hi @RobRayborn 

apparently Jihwan's solution works. 

 

I tried to simulate your case with such data:

FreemanZ_0-1678167327415.png

 

verified by creating a table visual with data, value columns and a measure like:

measure = 
VAR _date = MAX(TableName[date])
VAR _value =
MAXX(
    FILTER(
        ALL(TableName),
        TableName[date] = _date
    ),
    TableName[value]
)
VAR _datepre =
MAXX(
    FILTER(
        ALL(TableName),
        TableName[date] < _date
    ),
    TableName[date]
)
VAR _valuepre =
MAXX(
    FILTER(
        ALL(TableName),
        TableName[date] = _datepre
    ),
    TableName[value]
)
RETURN
DIVIDE(_value, _valuepre) -1

 

or like:

measure2 = 
VAR _date = MAX(TableName[date])
VAR _value =
MAXX(
    FILTER(
        ALL(TableName),
        TableName[date] = _date
    ),
    TableName[value]
)
VAR _valuepre =
MAXX(
    TOPN(
        1, 
        FILTER(
            ALL(TableName),
            TableName[date] < _date
        ),
        TableName[date]
    ),
    TableName[value]
)
RETURN
DIVIDE(_value, _valuepre) -1

 

it worked like:

FreemanZ_1-1678167468790.png

 

if you also accept calculated columns, try like:

column = 
VAR _datepre =
MAXX(
    FILTER(
        ALL(TableName),
        TableName[date] < EARLIER(TableName[date])
    ),
    TableName[date]
)
VAR _valuepre =
MAXX(
    FILTER(
        ALL(TableName),
        TableName[date] = _datepre
    ),
    TableName[value]
)
RETURN
DIVIDE([value], _valuepre) -1

or 

column2 = 
VAR _valuepre =
MAXX(
    TOPN(
        1, 
        FILTER(
            ALL(TableName),
            TableName[date] < EARLIER(TableName[date])
        ),        
        TableName[date]
    ),
   TableName[value]
)
RETURN
DIVIDE([value], _valuepre) -1

 

it worked like:

FreemanZ_2-1678167586001.png

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your datamodel looks like, but I tried to create a sample pbix file like below.

There are some ways to achieve this, and I think it depends on how the business process for Saturday and Sunday is defined. I assume there are blank (not zero) data on Sat and Sun, and one of ways to achieve this is using lastnonblank DAX function.

Jihwan_Kim_1-1678163509273.png

 

 

Jihwan_Kim_0-1678163477431.png

 

Diff %: =
VAR _currentdate =
    MAX ( 'Calendar'[Date] )
VAR _lastnonblank =
    CALCULATE (
        LASTNONBLANK ( 'Calendar'[Date], [Value sum:] ),
        FILTER ( ALL ( 'Calendar'[Date] ), 'Calendar'[Date] < _currentdate )
    )
VAR _lastnonblankvalue =
    CALCULATE ( [Value sum:], 'Calendar'[Date] = _lastnonblank )
RETURN
    IF (
        NOT ISBLANK ( [Value sum:] ) && HASONEVALUE ( 'Calendar'[Date] ),
        DIVIDE ( [Value sum:] - _lastnonblankvalue, _lastnonblankvalue )
    )

 



Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



This does what I asked for it to do, however it seems to have broken the TOTALYTD and DATESYTD measures.  I cannot produce a Rolling Annual amount with this solution.  Any ideas on how to fix this?

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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