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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
VannurVali
Helper I
Helper I

DAX Measure for Filling Blanks with Last Available Value

Hello everyone,

I need some suggestions  to achieve to fill blank values with last available date value. Below is my sample table.

DateMonthStore_IDProduct_CodeSales
01-01-20241A101100
01-02-20242A101 
01-03-20243A101400
01-01-20241B102300
01-02-20242B102 
01-03-20243B102500

Expected Behavior:

  • For February 2024 for Store A and Product 101, if the Sales is blank, it will take 100 (the Sales value from January 2024).
  • For March 2024 for Store B and Product 102, if the Sales is blank, it will take 500 (the Sales value from February 2024)

I need to calculate in the meausre please help on this .

Note : above table is just for your reference we don't have dates for blank rows we are taking from dim_calendar. we have data in below format in my fact table

DateMonthStore_IDProduct_CodeSales
01-01-20241A101100
01-03-20243A101400
01-01-20241B102300
01-03-20243B102500



Thanks.


1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1739145090456.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1739145090456.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur ,
Thanks for the quick response. It's working now, but I need to highlight the missing months in color.
Thanks!

You are welcome.  See this image

Ashish_Mathur_0-1739231882826.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

It is actually in my sample pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
danextian
Super User
Super User

Hi @VannurVali 

 

Please try the following:

Last Nonblank Value = 
SUMX (
    SUMMARIZECOLUMNS (
        Dates[Year],
        Dates[Month],
        'Table'[Store_ID],
        'Table'[Product_Code],
        "@value",
            IF (
                NOT ( ISBLANK ( [Sum of Sales] ) ),
                [Sum of Sales],
                CALCULATE (
                    LASTNONBLANKVALUE ( Dates[Month], [Sum of Sales] ),
                    FILTER ( ALL ( Dates ), Dates[Date] <= MAX ( Dates[Date] ) )
                )
            )
    ),
    [@value]
)

The cells highlighted in yellow are the latest values before the current month.

danextian_0-1739095172633.png

Please see the attached sample pbix.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
DataNinja777
Super User
Super User

Hi @VannurVali ,

 

To ensure optimal performance and maintainability, we will structure the data using a star schema. This means separating transaction-level data (FactSales) from descriptive information (DimDate, DimProduct, DimStore). The DimDate table is created using:

 

 

DimDate = ADDCOLUMNS (
    CALENDAR (DATE(2023,1,1), DATE(2025,12,31)),
    "Year", YEAR([Date]),
    "Month", FORMAT([Date], "MMM"),
    "Month Number", MONTH([Date])
)

 

 

With this setup, FactSales relates to DimDate through FactSales[Date] = DimDate[Date], ensuring that all time-based calculations are handled consistently.

Now, to fill missing sales values using the last available sales amount, we rewrite the DAX measure to fully respect the star schema by filtering based on DimDate[Date] instead of FactSales[Date]. This approach ensures that the measure is optimized for performance and properly leverages the date hierarchy.

 

 

Filled Sales = 
VAR LastSale =
    CALCULATE(
        MAX(FactSales[Sales]),
        FILTER(
            ALL(DimDate),
            DimDate[Date] < SELECTEDVALUE(DimDate[Date])
        ),
        FactSales[Store_ID] = SELECTEDVALUE(FactSales[Store_ID]),
        FactSales[Product_Code] = SELECTEDVALUE(FactSales[Product_Code]),
        NOT(ISBLANK(FactSales[Sales]))
    )
RETURN
    IF(
        ISBLANK(SELECTEDVALUE(FactSales[Sales])),
        LastSale,
        SELECTEDVALUE(FactSales[Sales])
    )

 

 

By filtering DimDate rather than FactSales, this measure properly aligns with the star schema. It ensures that missing sales values are filled using the last available value while keeping the calculations efficient. This also allows for better time intelligence integration and smoother performance in Power BI.

 

Best regards,

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.