Forum Discussion
Fill blanks with previous value
Hi All,
I have the current table below, which as you can see has missing values.
| Car | Month | Value |
| Fiat | Mar-08 | 10,000 |
| Fiat | Apr-08 | |
| Fiat | May-08 | |
| Fiat | Jun-08 | 12,000 |
| Fiat | Jul-08 | |
| Fiat | Aug-08 | |
| Audi | Mar-08 | 22,000 |
| Audi | Apr-08 | |
| Audi | May-08 | 24,000 |
| Audi | Jun-08 | |
| Audi | Jul-08 | 23,000 |
| Audi | Aug-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:
| Car | Month | Value | Value 2 |
| Fiat | Mar-08 | 10,000 | 10,000 |
| Fiat | Apr-08 | 10,000 | |
| Fiat | May-08 | 10,000 | |
| Fiat | Jun-08 | 12,000 | 12,000 |
| Fiat | Jul-08 | 12,000 | |
| Fiat | Aug-08 | 12,000 | |
| Audi | Mar-08 | 22,000 | 22,000 |
| Audi | Apr-08 | 22,000 | |
| Audi | May-08 | 24,000 | 24,000 |
| Audi | Jun-08 | 24,000 | |
| Audi | Jul-08 | 23,000 | 23,000 |
| Audi | Aug-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
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 dateValue2 = 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 ) )
7 Replies
- StachuCommunity Champion
if the goal is to have the table filled in you can achieve that in Power Query with few clicks
- AnonymousNot applicable
Unfortunately the table is outside of power query, is there a solution in DAX?
- StachuCommunity 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 dateValue2 = 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 ) )