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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
newgirl
Post Patron
Post Patron

New Table using Latest Distinct Value

Hi!

 

So I have this table that has consolidated list of client and the corresponding sales representative during the period.

 

ClientSales RepYearMonth
ABarney202001
BTed202001
CRobin202001
DLily202001
AMarshall202002
BTed202002
ERachel202002

 

 

What I need is to create a new table that will consolidate unique values from the client field but show corresponding sales representative based on latest date.

 

Desired new table:

ClientSales Rep
AMarshall
BTed
CRobin
DLily
ERachel

 

1 ACCEPTED SOLUTION
DataZoe
Microsoft Employee
Microsoft Employee

@newgirl I think @amitchandak works if you create it as a measure, then in a table visual add the Client and the Measure.

 

Last Sales Rep = LASTNONBLANKVALUE('Table'[YearMonth],max('Table'[Sales Rep]))

 

lastnonblank.JPG

 

 

 

If you want it as a seperate table, you could also do this:

 

Table 2 = SUMMARIZECOLUMNS('Table'[Client],"Last Sales Rep",[Last Sales Rep])

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

@newgirl - Some something like:

Table = 
  VAR __Table =
      ADDCOLUMNS(
        DISTINCT('Table'[Client])
        "Latest",
        MAX('Table'[YearMonth])
      )
  VAR __Table1 =
      __Table,
      "Sales Rep",
      MAXX(FILTER('Table','Table'[Client] = [Client] && 'Table'[YearMonth] = [Latest]),'Table'[Sales Rep])
RETURN
  __Table1


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi, @Greg_Deckler !

 

I tried your measure although I think it lacked a certain DAX formula in the _Table1. I guessed it was ADDCOLUMNS so this is the measure I did:

Table = 
  VAR __Table =
      ADDCOLUMNS(
        DISTINCT('Table'[Client]),
        "Latest",
        MAX('Table'[YearMonth])
      )
  VAR __Table1 =
      ADDCOLUMNS(
      __Table,
      "Sales Rep",
      MAXX(FILTER('Table','Table'[Client] = [Client] && 'Table'[YearMonth] = [Latest]),'Table'[Sales Rep])
      )
RETURN
  __Table1

 

 

However, it returned a table wherein the Client values were indeed unique but in the column for Sales Rep, it shows one Sales Rep value that is the same across all rows.

amitchandak
Super User
Super User

@newgirl , Try like

lastnonblankvalue(Table[YearMonth],max(Table[Sales Rep]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak !

 

I tried your suggested formula in creating a new table but it says "The expression specified in the query is not a valid table expression".

 

I think it's also missing certain fields? Because in the desired table, I need the column for Client and another column for the Sales Rep. 

DataZoe
Microsoft Employee
Microsoft Employee

@newgirl I think @amitchandak works if you create it as a measure, then in a table visual add the Client and the Measure.

 

Last Sales Rep = LASTNONBLANKVALUE('Table'[YearMonth],max('Table'[Sales Rep]))

 

lastnonblank.JPG

 

 

 

If you want it as a seperate table, you could also do this:

 

Table 2 = SUMMARIZECOLUMNS('Table'[Client],"Last Sales Rep",[Last Sales Rep])

 

Respectfully,
Zoe Douglas (DataZoe)



Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/

Hi, @DataZoe !

 

Thank you so much for your suggestion. It worked perfectly!

 

@newgirl , for the new table try

summarize(Table, Table[Client], "Sales Rep",lastnonblankvalue(Table[YearMonth],max(Table[Sales Rep])))

 

That was a measure you can use in visual 

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.