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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
vetty
Frequent Visitor

DAX Take the last non-null value in column until the new one arrives

Good Morning All,

I've searched around the web but found no solution. My problem maybe is simple but, I've no idea how to solve it.

power bi question.png

For each row in this dataset, I need to calculate the formula B/D*C and when the value of D column is Blank I want to use the last value until the new one arrives, as shown in the screenshot.

Thanks in advance 

1 ACCEPTED SOLUTION
SpartaBI
Community Champion
Community Champion

@vetty if you want to create this column in the model itslef in DAX, create this calculated column and use it for your calculations:

 

D Filled = 
VAR _currrentdate = 'Table'[A]
RETURN
    CALCULATE(
        LASTNONBLANKVALUE(
            'Table'[A],
            CALCULATE(SUM('Table'[D]))
        ),
        REMOVEFILTERS(),
        'Table'[A] <= _currrentdate 
    )

 

View solution in original post

6 REPLIES 6
SpartaBI
Community Champion
Community Champion

@vetty if you want to create this column in the model itslef in DAX, create this calculated column and use it for your calculations:

 

D Filled = 
VAR _currrentdate = 'Table'[A]
RETURN
    CALCULATE(
        LASTNONBLANKVALUE(
            'Table'[A],
            CALCULATE(SUM('Table'[D]))
        ),
        REMOVEFILTERS(),
        'Table'[A] <= _currrentdate 
    )

 

Thank you @SpartaBI it was what I'm trying to do. Also the solution from @amitchandak  works very well. Both solutions works also when the dataset refresh, so I'm pretty curious about which has the best performance. I think that @amitchandak solution is faster because power bi calculates the formula for the column every start. Any remarks will be appreciated

SpartaBI
Community Champion
Community Champion

@vetty 
The advantage in the Power Query solution is that you don't have an extra column in the model.
The disadvantage in the Power Query solution is that you need to make sure the table is sorted by dates before applying those steps. Sorting is an expensive operation. 
The dax solution will work regardless if the table is sorted before you bring it to the model.
Regarding refreshes, it depends on the folding of the query generated in Power Query to the data source. Both power query transformation and calculated cloumns are part of the refresh process of a model. It's not necessary that the Power Query solution is faster than the DAX option. In case the query is not folding good to the data source it can actually be slower that using the DAX option.
To sum it all up, as usual, the answer is: "It Depends" 🙂
Hope I was clear and that it helped you. 

Very Clear, Thank you again 😉

amitchandak
Super User
Super User

@vetty , Power query fill down

 

Power Query - Fill Up, Fill Down : https://www.youtube.com/watch?v=fuH29kkK12A&list=PLPaNVDMhUXGbfdGuSsfPR1qKBRT5Ywlki&index=5

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks, it work like a charm!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.