Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hi guys,
Does anyone know how to fill in blank values with the previous non blank value? I need this to be done with a dax measure because of my data model, as I'm using a date dimensional table.
The measure I'm currently using is this one:
PrecoMedioMovelv2 =
CALCULATE(
LASTNONBLANK(MaterialAvaliacao[PrecoMedioMovel];MaterialAvaliacao[PrecoMedioMovel]);
FILTER(ALL('Date'); 'Date'[Date] <= MAX('Date'[Date]))
)
But the problem is that it always returns the max value of the column MaterialAvaliacao[PrecoMedioMovel] for the given date context, as you can see in the picture below:
The desired output is the following:
Here's also the data model I'm using (for the current exercice, table MaterialMovimento doesn't need to be considered)
Thanks in advance!!
Solved! Go to Solution.
Hi @Anonymous ,
Here is the pbix. Glad it worked! PBIX FILE
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
Proud to be a Super User!
Hello @Anonymous ,
Try this:
PrecoMedioMovelv2 =
VAR _date =
MAX ( 'Date'[Date] )
RETURN
CALCULATE (
LASTNONBLANK (
MaterialAvaliacao[PrecoMedioMovel];
MaterialAvaliacao[PrecoMedioMovel]
);
FILTER ( ALLEXCEPT ( 'Date', 'Date'[Date] ); 'Date'[Date] <= _date )
)
This should get the date from the row that you are on.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
Proud to be a Super User!
Thanks for the quick answer.
But that measure returns the following error message: 'A single value for column 'Date' in table 'Date' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.'
Sorry try this.
PrecoMedioMovelv2 =
VAR _date =
MAX ( 'Date'[Date] )
RETURN
CALCULATE (
LASTNONBLANK (
MaterialAvaliacao[PrecoMedioMovel],
MaterialAvaliacao[PrecoMedioMovel]
),
FILTER ( ALLEXCEPT ( 'Date', 'Date'[Date] ), MAX ( 'Date'[Date] ) <= _date )
)
Proud to be a Super User!
It's returning 6,15 for every record..
In case you want to try, here's a link with the .pbix file: https://drive.google.com/drive/folders/1xtRMllYdA3HYsF0dzDa-UmnRTloDh6Ff?usp=sharing
Thanks!
Will do.
Proud to be a Super User!
Hi @Anonymous ,
Try this:
LastNonBlank Value =
VAR LastNonBlankDate =
CALCULATE (
MAX ( myTable[Date] ),
FILTER (
ALL ( myTable ),
myTable[Date] <= MAX ( myTable[Date] )
&& myTable[Value] <> 0
)
)
RETURN
CALCULATE (
SUM ( myTable[Value] ),
FILTER ( ALL ( myTable ), myTable[Date] = LastNonBlankDate )
)
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
Proud to be a Super User!
Thank you for your information .
Note :
If we cannot apply the
&& myTable[Value] <> 0
in measure the logic will be changed .
Hi @Anonymous ,
Here is the pbix. Glad it worked! PBIX FILE
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel
Proud to be a Super User!
How can i use the same logic but if i have an aditional column called "product"?
I want the same but taking in consideration the differents products.
Eg:
Dear @Nathaniel_C , thank you so much to share this solution. Worked very well for me.
Hi,
what if the column "value" isn't a number/integer/etc but text?
good to know.. my example is a sorted file.
Hi @Nathaniel_C
Sorry I know this is from a while ago but I just wondered, I am trying to do the same thing but with a text value therefore SUM cannot be used. Can I ask how you would chnge this to work for a STRING data type?
User | Count |
---|---|
23 | |
12 | |
10 | |
10 | |
8 |
User | Count |
---|---|
16 | |
15 | |
15 | |
14 | |
11 |