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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
polestar_11
Frequent Visitor

Lastnonblank / Fill Down with DAX Measure

I need your help: I’m trying to use a measurement (not a calculated column) to fill up the last value of the previous months in the months with empty values until a value appears again. Can you help me with the DAX Measure? I^ve tried it with the following Measure but the result was not right:

 

 

 

Lastnonblankvalue = 
CALCULATE(LASTNONBLANKVALUE('Date'[Date],SUM('Sales'[Value])))

 

 

 

polestar_11_3-1673965897359.png

 

 

It should look like:

 

polestar_11_1-1673960018923.png

 

Appreciate your help!

 

Information Dataset:

polestar_11_2-1673965838799.png

 

polestar_11_1-1673965823907.png

 

polestar_11_0-1673965809265.png

 

2 ACCEPTED SOLUTIONS
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @polestar_11 

Please try the following:

 

data model:

Mikelytics_0-1673968201407.png

 

Formula:

Repeat Last Value = 

var __SelectedDate = EOMONTH(MAX(Dim_Date[PK_Date]),0)

var __LastDateWithValue =
CALCULATE(
    MAX(Fact_Sales[Date]),
    FILTER(
        ALL(Dim_Date),
        [PK_Date]<=__SelectedDate
    )
)

RETURN

CALCULATE(
    TOTALMTD([Aggregation | Sum],Dim_Date[PK_Date]),
    Dim_Date[PK_Date] = __LastDateWithValue
)

Result

Mikelytics_1-1673968223696.png

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

Hi @polestar_11 

 

I think I found out the reason. Please add a year column in your ddate table and filter this column on 2021. Otherwise Power BI does not know what the max date is in the formula. Please see below.

 

When I filter on 2021 and 2022:

Mikelytics_0-1674079087404.png

 

when I put the filter on 2021.

 

Mikelytics_1-1674079113673.png

 

so even if you only have 2021 data please add a year column in the data table and put the filter on 2021. can also be done in page filter in the visual pane.

 

Mikelytics_2-1674079186163.png

 

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

5 REPLIES 5
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @polestar_11 

Please try the following:

 

data model:

Mikelytics_0-1673968201407.png

 

Formula:

Repeat Last Value = 

var __SelectedDate = EOMONTH(MAX(Dim_Date[PK_Date]),0)

var __LastDateWithValue =
CALCULATE(
    MAX(Fact_Sales[Date]),
    FILTER(
        ALL(Dim_Date),
        [PK_Date]<=__SelectedDate
    )
)

RETURN

CALCULATE(
    TOTALMTD([Aggregation | Sum],Dim_Date[PK_Date]),
    Dim_Date[PK_Date] = __LastDateWithValue
)

Result

Mikelytics_1-1673968223696.png

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

@Mikelytics Thank you for the answer. I've tried your solution but it is no as expected:

 

polestar_11_0-1674036965752.png

 

I am not sure if I changed the "TOTALMTD([Aggregation | SUM]" right.

 

Hi @polestar_11 

 

I think I found out the reason. Please add a year column in your ddate table and filter this column on 2021. Otherwise Power BI does not know what the max date is in the formula. Please see below.

 

When I filter on 2021 and 2022:

Mikelytics_0-1674079087404.png

 

when I put the filter on 2021.

 

Mikelytics_1-1674079113673.png

 

so even if you only have 2021 data please add a year column in the data table and put the filter on 2021. can also be done in page filter in the visual pane.

 

Mikelytics_2-1674079186163.png

 

 

Best regards
Michael
-----------------------------------------------------
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Appreciate your thumbs up!
@ me in replies or I'll lose your thread.

 

 

 

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Anonymous
Not applicable

Try the following:

LastNotBlank =
VAR _date =
    MAX ( 'Date'[Date] )
RETURN
    CALCULATE (
        LASTNONBLANK (
            Sales[Value];
            Sales[Value]
        );
        FILTER ( ALLEXCEPT ( 'Date', 'Date'[Date] ); 'Date'[Date] <= _date )
    )

 

@Anonymous Thank you for the answer.

 

It gives me the following Warning: 

polestar_11_0-1674028934882.png

 

For the Date column, it is not possible to obtain a single value in the Date table. This may happen when a measurement formula references a column with many values without specifying an aggregation such as MIN, MAX, COUNT, or SUM to obtain a single result.

 

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.