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
PelaezLink
Helper I
Helper I

Error in <expression> part in LASTNONBLANK function.

Hello everyone.

So I have the following DAX expression for a measure:

 

Measure = LASTNONBLANK(FACTCooperativa[Year]; FACTCooperativa[Ratio9PACA])
 
Basically in FACTCooperativa table I have an ID column, a Year column (which ranges between 2016 an 2020) and then some columns that represent values of certain ratios for each year and each ID number. This table always has a filter on, making it only have the date for one ID number. In reality the table has hundread of rows, 5 for each ID number (year 2016-2020) but because of the filter the table is all the time only with 5 rows. The thing is I want the Measure to give me the last year in which the value of 'Ratio9PACA' is not blank, but I get an error alway in the second part (<expression>). I do not know what is causing it. Error says:
"A single value for column 'R9PACA' in table 'FACTCooperativa' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."
I tried using the SELECTEDVALUE for the expression part but is not giving the correct results.
 
Thanks for all the help in advance.
 
1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

@PelaezLink 

 

Please have a look at the documentation first.

There are also examples of how to use this function -> LASTNONBLANK – DAX Guide

 

Assuming that certain conditions are met by your design, this might do the job:

[Measure] = 
LASTNONBLANK(
    FACTCooperativa[Year],
    // You need a context transition here.
    CALCULATE(
        SELECTEDVALUE( FACTCooperativa[Ratio9PACA] )
    )
)

 

 

View solution in original post

3 REPLIES 3
daXtreme
Solution Sage
Solution Sage

@PelaezLink 

 

Please have a look at the documentation first.

There are also examples of how to use this function -> LASTNONBLANK – DAX Guide

 

Assuming that certain conditions are met by your design, this might do the job:

[Measure] = 
LASTNONBLANK(
    FACTCooperativa[Year],
    // You need a context transition here.
    CALCULATE(
        SELECTEDVALUE( FACTCooperativa[Ratio9PACA] )
    )
)

 

 

Thank you very much that worked perfectly. I dont really understand why with CALCULATE does work but it does.

@PelaezLink 

 

Please learn about context transition. Then you'll understand. Start here: Understanding context transition in DAX - SQLBI

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.

Top Solution Authors