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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
J94
Helper I
Helper I

Fill blanks with previous values

Hi everyone, 

 

I want to show the sales per week. When there are no sales made for a week, I want to show the sales from the week before (or the week before that, etc. when there are sales made again. 


I created a simple sample dataset:

WeekBrandProduct_bkSales
1AAA110
1CCA150
1BBA125
2CCB2100
2BBB245
2AAB220
3CCC3150
3BBC365
3AAC330
4CCD4 
4BBD4250
4AAD4200
5CCE5 
5BBE5 
5AAE5 
6CCF6 
6BBF6 
6AAF6100


I had this measure for Brand level (based on a similar topic already asked: https://community.fabric.microsoft.com/t5/Desktop/Fill-blank-values-with-previous-value/td-p/1210628😞

Sales (fillblanks) =
VAR _weekwithsales =
    CALCULATE(MAX('Tabel'[Week]),
    FILTER(
        ALLEXCEPT('Tabel', Tabel[Brand]),
        'Tabel'[Week]<=MAX('Tabel'[Week]) && 'Tabel'[Sales]<>BLANK()
    )
    )
RETURN
CALCULATE(
    SUM([Sales]),
    'Tabel'[Week] = _weekwithsales, ALLEXCEPT('Tabel', Tabel[Brand])
)

This works, but I need it on Product_bk level. And that doesn't work, because the table doesn't have an empty row for every week for Product_bk where there are no sales. I did try to add blank rows for every week in Query Editor, but because the real dataset is larger, it wasn't able to handle that request. 
So, is there a way to change the measure for Product_bk? 
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@J94 Well, yeah, because in your data you don't have any previous sales for the products that are blank. You are basically running into an Auto Exist issue. Essentially you are attempting to invent data that doesn't exist. The measure is not going to calculate on rows it feels are invalid. They were supposed to have fixed the auto exist issue with allowing you to select "Independent" as the "Value filter behavior" for the semantic model but it doesn't work in all cases, like this one. Essentially, Power BI isn't even attempting to calculate the measure.

 

You could add a column and that should work but, again, you don't have any previous week sales in your data for the products that have blanks. So...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
J94
Helper I
Helper I

@Greg_Deckler thanks, I already thought it would be difficult to solve it with a measure. I will have a different approach and change the source instead. 

Greg_Deckler
Community Champion
Community Champion

@J94 Seems like it should be:

Measure = 
    VAR __Week = MAX( 'Table (5)'[Week] )
    VAR __Product = MAX( 'Table (5)'[Product_bk] )
    VAR __Sales = MAX( 'Table (5)'[Sales] )
    VAR __PreviousWeek = 
        MAXX(
            FILTER( 
                ALL( 'Table (5)' ),
                [Product_bk] = __Product && [Sales] <> BLANK() 
            ),
            [Week]
        )
    VAR __Previous = MAXX( FILTER( ALL( 'Table (5)' ), [Product_bk] = __Product && [Week] = __PreviousWeek ), [Sales] )
    VAR __Result = IF( __Sales = BLANK(), __Previous, __Sales )
RETURN
    __Result

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler , thanks for your reply. The Measure doesn't differ from the original Sales column unfortunalety. 

I added my file in Google Drive, so you can freely access it:
https://drive.google.com/file/d/1RGzJP_5movy2b3BmwH_fLJkc_A25fVLa/view?usp=drive_link

Greg_Deckler
Community Champion
Community Champion

@J94 Well, yeah, because in your data you don't have any previous sales for the products that are blank. You are basically running into an Auto Exist issue. Essentially you are attempting to invent data that doesn't exist. The measure is not going to calculate on rows it feels are invalid. They were supposed to have fixed the auto exist issue with allowing you to select "Independent" as the "Value filter behavior" for the semantic model but it doesn't work in all cases, like this one. Essentially, Power BI isn't even attempting to calculate the measure.

 

You could add a column and that should work but, again, you don't have any previous week sales in your data for the products that have blanks. So...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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