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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

Thanks, it work like a charm!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.