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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
igorabdo
Advocate II
Advocate II

Repeat last value

Hi folks

 

I've a question.Screenshot_1.png

For example.

If the number is blank, return the last data that is no blank.
For example.
In October, I don't have the value, so, bring the last that isn't blank. 

 



Best regards

2 ACCEPTED SOLUTIONS

Hello @igorabdo

 

I have normalized come columns and created the above model:

 

2018-10-02_10-15-33.jpg

 

Then I have used the below measure to calculate the figures:

 

 

Avg Cost Last Non Blank =
SUMX (
    Periods,
    VAR curPer = Periods[DATA_INICIO]
    RETURN
        IF (
            ISEMPTY ( RELATEDTABLE ( data ) ),
            CALCULATE (
                SUM ( data[CUSTO_MEDIO] ),
                LASTNONBLANK (
                    CALCULATETABLE ( Periods, Periods[DATA_INICIO] <= curPer ),
                    COUNTROWS ( RELATEDTABLE ( data ) )
                )
            ),
            CALCULATE ( SUM ( data[CUSTO_MEDIO] ) )
        )
)

 

Which is yielding the below results  ( I have conditionally formatted in red the figures that are calculated using the LASTNONBLANK part )

 

 

2018-10-02_10-21-37.jpg

 

I am not able to upload the file at the moment but if you still have doubts I will be able to upload it later in the day. 

 


 


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


Proud to be a Datanaut!  

View solution in original post

@igorabdo

 

You can download it here: https://1drv.ms/u/s!AiiWkkwHZChHjxV0PpsCKUIBzJVu

 

 


 


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


Proud to be a Datanaut!  

View solution in original post

7 REPLIES 7
LivioLanzo
Solution Sage
Solution Sage

Check out the LASTNONBLANK formula: https://www.sqlbi.com/articles/semi-additive-measures-in-dax/

 


 


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


Proud to be a Datanaut!  

No. 
I try but not sucess
Example

Hello @igorabdo

 

I have normalized come columns and created the above model:

 

2018-10-02_10-15-33.jpg

 

Then I have used the below measure to calculate the figures:

 

 

Avg Cost Last Non Blank =
SUMX (
    Periods,
    VAR curPer = Periods[DATA_INICIO]
    RETURN
        IF (
            ISEMPTY ( RELATEDTABLE ( data ) ),
            CALCULATE (
                SUM ( data[CUSTO_MEDIO] ),
                LASTNONBLANK (
                    CALCULATETABLE ( Periods, Periods[DATA_INICIO] <= curPer ),
                    COUNTROWS ( RELATEDTABLE ( data ) )
                )
            ),
            CALCULATE ( SUM ( data[CUSTO_MEDIO] ) )
        )
)

 

Which is yielding the below results  ( I have conditionally formatted in red the figures that are calculated using the LASTNONBLANK part )

 

 

2018-10-02_10-21-37.jpg

 

I am not able to upload the file at the moment but if you still have doubts I will be able to upload it later in the day. 

 


 


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


Proud to be a Datanaut!  

Hi LivioLanzo, thanks very much for your solution, it works great for me on the lowest level of data (PK_ITEM in your example) - but when I remove the items from a table visual and want to have a total per month then the numbers don't add up properly, would you know how to fix it?

Thanks.
Please, share you pbix.

 

Best regards.

@igorabdo

 

You can download it here: https://1drv.ms/u/s!AiiWkkwHZChHjxV0PpsCKUIBzJVu

 

 


 


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


Proud to be a Datanaut!  

Thanks very much @LivioLanzo

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.