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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
wsgjamesabl
Frequent Visitor

Fill in with last nonblank, but with measures

Hi everyone,

 

 

New Project.png

 I have sales broken out into a weekly view. The sales are a calculated measure, [Demand] and the SKU, [SKU], and Week Start Date, [Week Start date], are columns.
I'm trying to write a measure that says "look at the last non-blank value and copy it foward", i.e. the end result would be the number 19 being shown on weeks 1/17/2021 and 1/24/202.

I have an if statement already working, saying "if before 12/20/2020, ignore this formula", since I only care about the blanks being filled after then.
Currently (without the if statement above) my formula is adding the measure [Demand]
This is my formula below:


=
CALCULATE([Demand],
FILTER(ALL('All Transactions'),
'All Transactions'[Week Number] = SELECTEDVALUE('All Transactions'[Week Number]) -1
&&
'All Transactions'[Year] = SELECTEDVALUE('All Transactions'[Year])
))

But when I run the measure, it does this instead:

 

Capture.PNG

 

 

Is there any way someone can help me out? Essentially, I'm trying to use the LASTNONBLANK() formula, but that doesn't work unless it's referencing a column
I've looked throughout the community and found these similar situations, but couldn't figure out why this isn't working. (There are no other tables, so it's not a connection issue imo)

 

 

 

Thank you for your time and help!

Jake

1 REPLY 1
MFelix
Super User
Super User

Hi @wsgjamesabl ,

 

Don't know how your model is setup and what is the DEMAND formula but believe you can do something similar to this.

 

Create a table with the week values:

WeeksDates = DISTINCT('Cost'[Date])

 

Now add the following measure:

TotalOrders = 
VAR temp_table =
    SUMMARIZE (
        FILTER ( ALL ( 'Cost' ); 'Cost'[Date] < MAX ( 'WeeksDates'[Date] ) );
        'Cost'[Date];
        'Cost'[SKU];
        'Cost'[Quantity]
    )
VAR totalQuantity =
    CALCULATE (
        SUM ( 'Cost'[Quantity] );
        TREATAS ( VALUES ( 'WeeksDates'[Date] ); 'Cost'[Date] )
    )
VAR MaximumDate =
    MAXX (
        FILTER ( temp_table; 'Cost'[SKU] IN VALUES ( 'Cost'[SKU] ) );
        'Cost'[Date]
    )
VAR Demand =
    SUMX (
        FILTER (
            temp_table;
            'Cost'[SKU]
                IN VALUES ( 'Cost'[SKU] )
                    && 'Cost'[Date] = MaximumDate
        );
        Cost[Quantity]
    )
RETURN
    IF ( ISBLANK ( totalQuantity ); Demand; totalQuantity )

 

See result below:

 
 
 

orders.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.

Top Solution Authors