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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RitaFFFF1233
Frequent Visitor

last non blank value on date without transaction

Hello,
There are two tables in my database: one with transaction date and transaction value, as shown in the table below.
Second, dates table.
For every day in the chosen period (by dates table), I need to show values. If there is no transaction on some day, I should show the last transaction with its value.
I tried using some variations of function LASTNONBLANK without success.
I would appreciate your assistance.
link to PBIX :
PBIX last no blank 

 

Date

 sum
01/02/2023 3
02/02/2023 5
05/02/2023 6
06/02/2023 7
08/02/2023 8
2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1676615229546.png

 

 

Lastnonblank value: = 
VAR _currentyear =
    MAX ( DateTable[Year] )
VAR _lastnonblankyear =
    CALCULATE (
        LASTNONBLANK ( DateTable[Year], [totalValue] ),
        FILTER ( ALL ( DateTable[Year] ), DateTable[Year] <= _currentyear )
    )
RETURN
    IF (
        HASONEVALUE ( Suppliers[SupplierName] ),
        CALCULATE ( [totalValue], DateTable[Year] = _lastnonblankyear )
    )

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

 Thank you for your response.
I updated your code to 

Lastnonblank value: =
VAR _maxDate =
    MAX ( 'Table (2)'[Date] )
VAR _lastnonblankdate =
    CALCULATE (
        LASTNONBLANK ('Table (2)'[Date], [total sum]),
        FILTER ( ALL ('Table (2)'[Date]),'Table (2)'[Date] <= _maxDate )
    )
RETURN
         CALCULATE ( [total sum],'Table (2)'[Date] = _lastnonblankdate )
Worked perfectrly for me

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1676615229546.png

 

 

Lastnonblank value: = 
VAR _currentyear =
    MAX ( DateTable[Year] )
VAR _lastnonblankyear =
    CALCULATE (
        LASTNONBLANK ( DateTable[Year], [totalValue] ),
        FILTER ( ALL ( DateTable[Year] ), DateTable[Year] <= _currentyear )
    )
RETURN
    IF (
        HASONEVALUE ( Suppliers[SupplierName] ),
        CALCULATE ( [totalValue], DateTable[Year] = _lastnonblankyear )
    )

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

 Thank you for your response.
I updated your code to 

Lastnonblank value: =
VAR _maxDate =
    MAX ( 'Table (2)'[Date] )
VAR _lastnonblankdate =
    CALCULATE (
        LASTNONBLANK ('Table (2)'[Date], [total sum]),
        FILTER ( ALL ('Table (2)'[Date]),'Table (2)'[Date] <= _maxDate )
    )
RETURN
         CALCULATE ( [total sum],'Table (2)'[Date] = _lastnonblankdate )
Worked perfectrly for me

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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