Say I am importing something like the following into PowerBI:
Date | Quantity
|---------------------|------------------|
| 1/1/2018 | 22 |
| 1/3/2018 | 30 |
| 1/4/2018 | 10 |
|---------------------|------------------|
Where the external source table is a series of date, value rows with some date values missing. I'd like to execute some DAX/M to add any missing date rows into the data set, where 'Quantity' value is taken from the first date prior. So my resulting dataset would like like this:
Date | Quantity
|---------------------|------------------|
| 1/1/2018 | 22 |
| 1/2/2018 | 22 |
| 1/3/2018 | 30 |
| 1/4/2018 | 10 |
|---------------------|------------------|
Can this be done in PowerBI?
Help is much appreciated!
You can do this in DAX by creating a new table with all of the dates in your range as follows:
FullTable =
ADDCOLUMNS(
CALENDAR(MIN(Table1[Date]), MAX(Table1[Date])),
"Quantity",
LOOKUPVALUE(
Table1[Quantity],
Table1[Date],
MAXX(
FILTER(Table1, Table1[Date] <= EARLIER([Date])),
[Date]
)
)
)
The CALENDAR
function gives you a range of dates from you minimum to maximum dates in your original table. From there, we add a new column, Quantity
, and define it as the value we get when looking up the Quantity
in the original table for the date that was the maximum date occurring on or before the date in the current row.