Forum Discussion
Fill blank values with last not blank value
Hello!
I have a table with multiple products and duplicated dates where I need to show the last registered price, I tried using a calculated column but it consumes a lot of memory for my computer, is there a way to do this as a measure with DAX? To give an example this is how my table looks like (For date I'm using a date table which is connected to the table with the prices and products):
Date | Product | Price |
| 12-31-2023 | A | 1 |
| 12-31-2023 | B | 2 |
| 01-01-2024 | A | |
| 01-01-2024 | B | |
| 01-02-2024 | A | 3 |
| 01-02-2024 | B | 5 |
| 01-03-2024 | A | |
| 01-03-2024 | B | 6 |
And here is my desired result:
Date | Product | Price |
| 12-31-2023 | A | 1 |
| 12-31-2023 | B | 2 |
| 01-01-2024 | A | 1 |
| 01-01-2024 | B | 2 |
| 01-02-2024 | A | 3 |
| 01-02-2024 | B | 5 |
| 01-03-2024 | A | 3 |
| 01-03-2024 | B | 6 |
Thank you for any advice 😊
Asmonk , Try a measure like below. However large data may slow down the measure too
measure =
If(isblank(max(Table[Price])), calculate(lastnonblankvalues(Table[Date], max(Table[Price])), filter(all(Table), Table[Product] = Max(Table[Product]) && Table[Date] <= max(Table[Date]))),max(Table[Price]) )
- Anonymous2 years ago
Hi Asmonk ,
amitchandak Nice answer!
Have you solved your problem? If not, when you use DAX to solve it, both the measure and calculated columns take up more computer memory. If you can use Power Query, you can try this way and it will reduced computer memory footprint:
First, please Duplicate the original Table:And in the Table(2), filter Product = A:
Select Column Price and click Fill down, and the output is as below:
In Table(3), filter Product = B and do the same Fill down on Column Price, and the output is as below:
Select original Table and click Merge Queries as New:
The output is as below:
Expand the column:
And Merge Queries as New again:
Expand again:
The output is as below:
Choose this two columns and click merge columns:
The final output is as below:
The above method is realized by operation, here we provide a simpler but need to be realized by M function. Just put the following code into Advanced Editor:let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTSNzbUNzIwMlbSUXIEYkOlWB00YScgNoII64MFTaBq0cWcEGJGyOqM0QVBCk2hgsZYTDRGVmimFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Product = _t, Price = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Product", type text}, {"Price", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Count", each Table.FillDown(_,{"Price"})}}), #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Date", "Price"}, {"Count.Date", "Count.Price"}) in #"Expanded Count"The final output is the same:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Hi,
PBI file attached.
Hope this helps.
3 Replies
- amitchandak
Super User
Asmonk , Try a measure like below. However large data may slow down the measure too
measure =
If(isblank(max(Table[Price])), calculate(lastnonblankvalues(Table[Date], max(Table[Price])), filter(all(Table), Table[Product] = Max(Table[Product]) && Table[Date] <= max(Table[Date]))),max(Table[Price]) )
- Ashish_Mathur
Super User
- AnonymousNot applicable
Hi Asmonk ,
amitchandak Nice answer!
Have you solved your problem? If not, when you use DAX to solve it, both the measure and calculated columns take up more computer memory. If you can use Power Query, you can try this way and it will reduced computer memory footprint:
First, please Duplicate the original Table:And in the Table(2), filter Product = A:
Select Column Price and click Fill down, and the output is as below:
In Table(3), filter Product = B and do the same Fill down on Column Price, and the output is as below:
Select original Table and click Merge Queries as New:
The output is as below:
Expand the column:
And Merge Queries as New again:
Expand again:
The output is as below:
Choose this two columns and click merge columns:
The final output is as below:
The above method is realized by operation, here we provide a simpler but need to be realized by M function. Just put the following code into Advanced Editor:let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTSNzbUNzIwMlbSUXIEYkOlWB00YScgNoII64MFTaBq0cWcEGJGyOqM0QVBCk2hgsZYTDRGVmimFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Product = _t, Price = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Product", type text}, {"Price", Int64.Type}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Product"}, {{"Count", each Table.FillDown(_,{"Price"})}}), #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Date", "Price"}, {"Count.Date", "Count.Price"}) in #"Expanded Count"The final output is the same:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.