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

Trying to calculate most recent classification

Suppose there are three columns:

 

CLIENT | Classification | Date

1          |   A                  | 1/1/2016

1          |   A                  | 1/1/2016

1          |   B                  | 2/1/2016

1          |  C                  | 3/1/2016

1          |  A                  | 4/1/2016

2          |   B                | 1/1/2016

2          |   B                  | 2/1/2016

2          |  A                  | 3/1/2016

2          |   A                 | 3/1/2016

2          |  C                  | 4/1/2016

 

 

How would I grab the most recent Classification for each client to output:

 

Client | Classification

1        | A

2        | C

 

I've tried multiple things but everything always returns all combinations e.g.

1        | A

1        | B

1        | C

2        | A

2        | B

2        | C

 

 

Any help?

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@Casteless

 

How about this?

 

Classification on Last Date =
IF (
    HASONEVALUE ( 'Table'[Client] ),
    CALCULATE (
        LASTNONBLANK ( 'Table'[Classification], 1 ),
        LASTDATE ( 'Table'[Date] )
    ),
    BLANK ()
)

Good Luck! Smiley Happy

View solution in original post

14 REPLIES 14
Vvelarde
Community Champion
Community Champion

@Casteless

 

Hi, please watch the video and let me know if helps you-

 

 




Lima - Peru

Hi Vvelarde, 

 

That won't work as the rest of the values in the table require aggregation across a range of dates.

As such the |Date| column can't be  a part of the visual

 

Thanks for the attempt!

@Casteless

 

try with this:

 

LastClassification = CALCULATE(VALUES(Table2[Classification]),LASTDATE(Table2[Date]))




Lima - Peru

That will return a multiple values error (even if i add distinct). 

@Casteless

 

Can you have different classification in same day for a client?

 

Using your sample Data i have this result

 

clas.png




Lima - Peru

Well this is odd, are you sure you copied in the duplicate dates?

I am also using the sample data and I recieve the multiple values error.

 

the measure:

class2 = CALCULATE(VALUES(Testtable[class]),LASTDATE(Testtable[date]))

 

the data: Testtable

table.png

 

 

@Casteless

 

To solve the error you can put the Table's Total OFF.

 

The error appears because in totals, you have 2 or more rows with last date (Example: 4/1/16). If you don't want to switch off the totals you need to add to dax formula:

 

 

 Class2 = IF(HasOneValue(Testtable[client]),CALCULATE(VALUES(Testtable[class]),LASTDATE(Testtable[date])))

 




Lima - Peru

Ah the problem was in the "totals" option again, why must that be turned to off for this to work?

For some reason when i try to use this solution with my real data the "General" section of format is not available? so i can't turn off totals.

Why can i not turn off totals in the table as suggested?

 

table.png

 

@Casteless

 

Try to Delete the measure of the visual and add again.

 

Regards,

 

 

 




Lima - Peru
Sean
Community Champion
Community Champion

@Casteless

 

How about this?

 

Classification on Last Date =
IF (
    HASONEVALUE ( 'Table'[Client] ),
    CALCULATE (
        LASTNONBLANK ( 'Table'[Classification], 1 ),
        LASTDATE ( 'Table'[Date] )
    ),
    BLANK ()
)

Good Luck! Smiley Happy

Sean,

That works perfectly!

I tried to use LastnonBlank in my original attempts but was lacking an expression.

I was unaware you could put "1" for an expression, what does that mean?

 

VVlarde thanks for your help as well!

Sean
Community Champion
Community Champion

@Casteless

"placing 1 as the second parameter has the same effect as just ignoring this parameter"

 

You can read more about it here...

http://exceleratorbi.com.au/lastnonblank-explained/

 

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.