Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Help with FIRSTNONBLANK

Here is the forumla for a new column:  

CALCULATE(FIRSTNONBLANK('HEADCOUNT'[Location],TRUE()),Filter('HEADCOUNT','HEADCOUNT'[Unique Employee Number]='TERMINATIONS'[UEN]))

 

  • The idea is to populate the Location from Headcount onto Terminations. 
  • I need to populate it from the row with the LATEST Headcount data, which is appended to the database monthly.
    I sorted the Headcount table Descending according to the run date, both in the Query editor and the Table view.
  • It's not pulling the first non blank row - as if it is ignoring the sorting, or the Filter Expression in Calculate amends it.

Does anyone know what is going on here?

  • Hi Anonymous

    As tested, just as you said,it is ignoring the sorting.

    We should know that FirstNonBlank is like using a MIN function and will return the lowest value rather than the first item in a sequence.

     

    Per your requirement, you want to get the the first not blank Location value for each Unique Employee Number based on the run date in Descending order in table Headcount, then put the value in the table Terminations.

     

    As i tested, here is a workaround without using FirstNonBlank.

    calculated column in table Headcount
    firstnoblank =
    CALCULATE (
        LASTNONBLANK ( HEADCOUNT[Location], TRUE () ),
        ALLEXCEPT ( HEADCOUNT, HEADCOUNT[Unique Employee Number] )
    )

     

     

    column created in table Terminations
    
    Column = LOOKUPVALUE(HEADCOUNT[firstnoblank],HEADCOUNT[Unique Employee Number],ERMINATIONS[UEN])

     

     

    Best Reagrds

    Maggie

2 Replies

  • v-juanli-msft's avatar
    v-juanli-msft
    Community Support

    Hi Anonymous

    As tested, just as you said,it is ignoring the sorting.

    We should know that FirstNonBlank is like using a MIN function and will return the lowest value rather than the first item in a sequence.

     

    Per your requirement, you want to get the the first not blank Location value for each Unique Employee Number based on the run date in Descending order in table Headcount, then put the value in the table Terminations.

     

    As i tested, here is a workaround without using FirstNonBlank.

    calculated column in table Headcount
    firstnoblank =
    CALCULATE (
        LASTNONBLANK ( HEADCOUNT[Location], TRUE () ),
        ALLEXCEPT ( HEADCOUNT, HEADCOUNT[Unique Employee Number] )
    )

     

     

    column created in table Terminations
    
    Column = LOOKUPVALUE(HEADCOUNT[firstnoblank],HEADCOUNT[Unique Employee Number],ERMINATIONS[UEN])

     

     

    Best Reagrds

    Maggie