Forum Discussion

SO's avatar
SO
Helper III
4 years ago
Solved

Missing "LastNONBLANKVALUE" Dax function.

Hello,

 

I am trying to find the last value from a table, and was experimenting with LastNonBlank and wasn't getting the correct result and then read some more and realized that I think I should be using LastNonBlankValue, but this Dax function is missing and is not in my latest version of PBI (downloaded January 2022).   Update... I have this function in my data sets that are not live (InService).  Does it not exist in Service? 

 

 

My data looks something like:

LocationIDModelStart DateEnd DateCountStatus
1101F9/9/20219/24/20211a
1101R9/25/20216/30/20221a
1102F9/9/202110/1/20211a
1102R10/2/202110/30/20211a
1102F11/1/20216/30/20221a
2989R 9/9/20216/30/20221a
3988R 9/9/20216/30/20221a
4222R9/9/202111/17/20211a
4222F1/4/20226/30/20221x

 

Using the LastNonBlankValue I was hoping to get to the table below so that I could then use this information to filter values in another table,  

 

Location ID Model Start Date End Date Count Status
1101R9/25/20216/30/20222a
1102F11/1/20216/30/20223a
2989R 9/9/20216/30/20221a
3988R 9/9/20216/30/20221a
4222F1/4/20226/30/20222x

 

My Measure is currently, 

 

# Last2 = LASTNONBLANK('SET'[Startdate], max(SET[Model]))

 

but this only gives me the starting date and does not filter.  I assume it is because I'm not looking at the value.  

 

LocationIDModelStart DateEnd DateCountStatusLast
1101F9/9/20219/24/20211a9/9/2021
1101R9/25/20216/30/20221a9/25/2021
1102F9/9/202110/1/20211a9/9/2021
1102R10/2/202110/30/20211a10/2/2021
1102F11/1/20216/30/20221a11/1/2021
2989R 9/9/20216/30/20221a 9/9/2021
3988R 9/9/20216/30/20221a 9/9/2021
4222R9/9/202111/17/20211a9/9/2021
4222F1/4/20226/30/20221x1/4/2022

 

I was looking at 
@mahoneypa

https://community.powerbi.com/t5/Desktop/Get-the-last-non-blank-value-of-a-column-with-DAX/td-p/1694566

 

and DataInsights https://community.powerbi.com/t5/Desktop/How-to-get-the-lastnonblank-value-when-I-need-to-keep-several/td-p/1746240 

but can't seem to replicate the answer.  Thoughts?  

  • Dear Ashish Mathur, 

     

    I am simply in awe!  Thank you so much!  It is going to take me some time to understand why and how this works.  Thank You - Thank You!!   

    Here I was focusing on the one function and you found such an elegant approach.    This is so kind of you.  I very much appreciate this support.  People like you make this such a wonderful community!  

4 Replies

  • SO's avatar
    SO
    Helper III

    Dear Ashish Mathur, 

     

    I am simply in awe!  Thank you so much!  It is going to take me some time to understand why and how this works.  Thank You - Thank You!!   

    Here I was focusing on the one function and you found such an elegant approach.    This is so kind of you.  I very much appreciate this support.  People like you make this such a wonderful community!  

  • Nice solution, Ashish_Mathur. This helped sharpen my understanding of LASTNONBLANK.

     

    In case anyone encounters a performance issue (see link below), here's an alternative approach:

     

    Last Model = CALCULATE ( MIN ( Data[Model] ), Data[Start Date] = MAX ( Data[Start Date] ) )

     

    Last Status = CALCULATE ( MIN ( Data[Status] ), Data[Start Date] = MAX ( Data[Start Date] ) )

     

    The September 2021 release introduced the use of aggregation functions in CALCULATE filters when they are used in Boolean (True/False) expressions. The expression MAX ( Data[Start Date] ) evaluates in the filter context of the visual, resulting in the appropriate date being used for each Location and ID.

     

    https://www.sqlbi.com/articles/optimizing-lastnonblank-and-lastnonblankvalue-calculations/