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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
RicPT
Regular Visitor

Problem with filling empty spaces in column

I'm having a problem with PowerBI dax. I have a table with two columns, Index and Value, and i need a new column that is filled with the last non blank value of column Value, as shown next:

 

RicPT_0-1712843671045.png

I'm using the following DAX expression

 

filledColumn=

CALCULATE(
    LASTNONBLANK('Table'[Value], TRUE()),
    FILTER(
        ALL('Table'),
        'Table'[index] <= EARLIER('Table'[index])
    )
)
 
The result is the following: 
RicPT_1-1712843807283.png

Everytime the last non blank cell of "value" has a smaller value than the previous one, it keeps filling the new column with the older value; it will only update if a bigger number than the previous fill number appears on a row of "value . Can you help me with this? is there an alternative way of doing it using dax? Thank you so much!

1 ACCEPTED SOLUTION

Hi @RicPT ,

Based on my testing again, please try the following DAX formula:

1.Create the new column and enter the following DAX formula.

 

filledcolumn = 
var index_ = 'Table'[Index]
RETURN
CALCULATE(
    LASTNONBLANK('Table'[Value], TRUE()),
    FILTER(
        ALL('Table'),
        'Table'[index] <= index_
    )
)

 

2.Drag the column into the table visual. The result is shown below.

vjiewumsft_0-1713149008020.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
HarishKM
Impactful Individual
Impactful Individual

@RicPT Hey,
you can use  this feature of Power query. I am sharing a link with you to have a look.

Fill values in a column - Power Query | Microsoft Learn


above feature will give the similer result and less load.

 

 

Thanks

Harish

If I solve this issue Kindly give kudos and accept this solution.

Thank you for your help! It's great in PowerQuery but not available in table view 🙂 Thank you for your time. Have a nice weekend!

v-jiewu-msft
Community Support
Community Support

Hi @RicPT ,

First of all, many thanks to @johnbasha33  for your very quick and effective replies.

Based on my testing, please try the following alternative formula:

1.Create the simple table.

vjiewumsft_0-1712899154855.png

2.Create the new measure to fill empty space.

 

FilledColumn = 
VAR index_ = SELECTEDVALUE('Table'[Index])
RETURN
CALCULATE(
    LOOKUPVALUE('Table'[Value], 'Table'[Index], MAX('Table'[Index])),
    FILTER(
        ALL('Table'),
        'Table'[Index] <= index_ && NOT(ISBLANK('Table'[Value]))
    )
)

 

3.Drag the measure into the table visual. The result is shown below.

vjiewumsft_1-1712899201351.png

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you for your help. I confirmed it works in table visualization but i was trying something else. Most likely i'm not doing the right thing, but my interest was to fill the column in table view. I will try a different logic for this. Thank you for your time!

 

RicPT_0-1712944799591.png

 

 

Hi @RicPT ,

Based on my testing again, please try the following DAX formula:

1.Create the new column and enter the following DAX formula.

 

filledcolumn = 
var index_ = 'Table'[Index]
RETURN
CALCULATE(
    LASTNONBLANK('Table'[Value], TRUE()),
    FILTER(
        ALL('Table'),
        'Table'[index] <= index_
    )
)

 

2.Drag the column into the table visual. The result is shown below.

vjiewumsft_0-1713149008020.png

 

Best Regards,

Wisdom Wu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

johnbasha33
Solution Sage
Solution Sage

@RicPT 

It seems like you want to fill a new column with the last non-blank value from the "Value" column, but you're encountering issues when the last non-blank value is smaller than the previous one. This is because your current DAX expression doesn't consider the order of values correctly.

To achieve the desired result, you can modify your DAX expression to consider the order of rows based on the "Index" column. Here's how you can do it:

```DAX
filledColumn =
VAR LastNonBlankValue =
CALCULATE (
LASTNONBLANK ( 'Table'[Value], TRUE () ),
FILTER ( ALL ( 'Table' ), 'Table'[index] <= EARLIER ( 'Table'[index] ) )
)
RETURN
CALCULATE (
MAXX ( FILTER ( 'Table', 'Table'[index] <= EARLIER ( 'Table'[index] ) ), 'Table'[Value] ),
FILTER ( ALL ( 'Table' ), 'Table'[Value] = LastNonBlankValue )
)
```

This expression calculates the last non-blank value from the "Value" column and then finds the maximum value of "Value" up to the current row where the "Value" is equal to the last non-blank value. This ensures that the filled column gets updated with the latest value if it's greater than the previous one.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

Thank you so much for the help. Unfortunately, the expression MAXX ( FILTER ( 'Table', 'Table'[index] <= EARLIER ( 'Table'[index] ) ), 'Table'[Value] ),  always results on an error "EARLIER/EARLIEST refers to an earlier row context which doesn't exist." as it doesn't recognize the input 'Table'[index]. This only happens in the MAXX filter, not in the FILTER ( ALL ( 'Table' ), 'Table'[index] <= EARLIER ( 'Table'[index] ) ). Thanks again for the time you've all taken to help me.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.