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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Fill blanks with previous value

Hi All,

 

I have the current table below, which as you can see has missing values.

 

CarMonthValue
FiatMar-0810,000
FiatApr-08 
FiatMay-08 
FiatJun-0812,000
FiatJul-08 
FiatAug-08 
AudiMar-0822,000
AudiApr-08 
AudiMay-0824,000
AudiJun-08 
AudiJul-0823,000
AudiAug-08 

 

I need to create a calculated column which fills in those blanks based on the last month for that type of car, so something like this:

 

CarMonthValueValue 2
FiatMar-0810,00010,000
FiatApr-08 10,000
FiatMay-08 10,000
FiatJun-0812,00012,000
FiatJul-08 12,000
FiatAug-08 12,000
AudiMar-0822,00022,000
AudiApr-08 22,000
AudiMay-0824,00024,000
AudiJun-08 24,000
AudiJul-0823,00023,000
AudiAug-08 23,000

 

Does anyone have any ideas how to do this? The issue of offsetting is where there are more than two blank rows in sequence.

 

Thanks,

 

Jack

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

what do you mean by 'outside of Power Query'? is it calculated table?
in DAX you can try this, it works as long as Month column has type date

Value2 =
VAR CurrentCar = 'Table'[Car]
VAR CurrentDate = 'Table'[Month]
VAR LastDateWithValue =
    CALCULATE (
        MAX ( 'Table'[Month] ),
        FILTER (
            'Table',
            'Table'[Value] <> BLANK ()
                && 'Table'[Car] = CurrentCar
                && 'Table'[Month] <= CurrentDate
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[Car] = CurrentCar
                && 'Table'[Month] = LastDateWithValue
        )
    )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

7 REPLIES 7
Stachu
Community Champion
Community Champion

if the goal is to have the table filled in you can achieve that in Power Query with few clicks
Capture.PNG



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Anonymous
Not applicable

Unfortunately the table is outside of power query, is there a solution in DAX?

Stachu
Community Champion
Community Champion

what do you mean by 'outside of Power Query'? is it calculated table?
in DAX you can try this, it works as long as Month column has type date

Value2 =
VAR CurrentCar = 'Table'[Car]
VAR CurrentDate = 'Table'[Month]
VAR LastDateWithValue =
    CALCULATE (
        MAX ( 'Table'[Month] ),
        FILTER (
            'Table',
            'Table'[Value] <> BLANK ()
                && 'Table'[Car] = CurrentCar
                && 'Table'[Month] <= CurrentDate
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[Car] = CurrentCar
                && 'Table'[Month] = LastDateWithValue
        )
    )


Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Hi @Stachu 
I tried your code, but it says a single value for column 'car' in table cannot be determined. could you please help

Hi @Stachu ,
I have same case, but the data type of column that need to fill is "Text? type. I try to using your dax but got an erro because SUM dax can used for data type of text.

basically I have column like this, I need to fill the "status" based on previous date with same school ID.

Any help will be really appreciate.

School IDDateStatus
11 nov 2021High
21 nov 2021Medium 
31 nov 2021Low
12 nov 2021High
22 nov 2021Low
32 nov 2021 
   
   

Hi,
I have a similar situation for me with forward filling of text based on conditions. The logic with SUM works well for numeric. Your solution will greatly help me. Thanks in Advance.

Regards.

Anonymous
Not applicable

I used your query and to me, it fills the previous value to blank rows but add some garbage value to existing row value

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors