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
Anonymous
Not applicable

Unique column values

Hi 

 

I am trying to get a table wth cst and sales rep based on the last order date

 

so I have a table 

Customer #Sales RepLast order date
1018574tim9/21/2017
1018574alex9/22/2017
1017640dirk1/12/2018
1017640pit8/23/2017
1017640john10/24/2017
1020601kris1/11/2018
1020601michael12/15/2017
1015972Lisa1/11/2018
1015972carsten1/15/2018
1015972maria9/4/2017
1015972tom12/28/2017
1015981carsten11/13/2017
1015981niels1/15/2018
1020722jenny12/1/2017
1020722peter1/4/2018

 

 

and I would like to get a new table which will look like this

 

1018574alex
1017640dirk
1020601kris
1015972carsten
1015981niels
1020722peter

 

 

thank you 

 



1 ACCEPTED SOLUTION

@Anonymous

 

As a calculated column you could use

 

Column =
VAR MyMax =
    CALCULATE (
        MAX ( TableName[Last order date] ),
        ALLEXCEPT ( TableName, TableName[Customer #] )
    )
RETURN
    CALCULATE (
        FIRSTNONBLANK ( TableName[Sales Rep], 1 ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Customer #] ),
            TableName[Last order date] = MyMax
        )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

12 REPLIES 12
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous

 

It works when I use the sample data you have provided. See the pic below

 

Could you show me a screenshot of your formula?

 

or share the file via onedrive or googledrive

 

7513.png

 


Regards
Zubair

Please try my custom visuals
vanessafvg
Super User
Super User

@Anonymous just create a dax measure do a LastDate = lastdate(datefield) and use the LastDate





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Anonymous
Not applicable

Thanx @vanessafvg

 

That doesnt work because i have multiple sales reps per customer. 

Example customer

1015970 was maintained by sales rep maria in sept 2017, by tom in december 2017, by lisa on the 11th of Jan and finaly by Tom on 15th of Jan 2018

 

I would like to see only TOM

 

Thats why i am trying to get a column where i will see the last date per customer and then use it in another column where i would liek to use if function or something like that.. 

 

would be great if you can help me somehow becasue i am really strugeling here.. 

 

thanx for your time

 

 

 

 

@Anonymous ok you need to  summarzie the table in my opinion

 

summarizetable = SUMMARIZE(data,Data[Customer #], Data[Sales Rep], "Lastdate",  max(Data[Last order date]) )

 

from the new table you should be abel to pull the last per record

 

 





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@Anonymous

 

Try this MEASURE.
Then Drag Customer # and this MEASURE to  a TABLE visual

 

LastSalesRep =
CALCULATE (
    SELECTEDVALUE ( TableName[Sales Rep] ),
    FILTER (
        TableName,
        TableName[Last order date] = MAX ( TableName[Last order date] )
    )
)

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Hi @Zubair_Muhammad

 

This looks promissing however i get this error for some reason 

 

"The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."

 

what can be this linked to  

Hi @Anonymous

 

Try this revision

 

LastSalesRep =
CALCULATE (
    FIRSTNONBLANK ( TableName[Sales Rep], 1 ),
    FILTER (
        TableName,
        TableName[Last order date] = MAX ( TableName[Last order date] )
    )
)

Regards
Zubair

Please try my custom visuals

@Anonymous

 

Error might be due to the fact that there could be 2 sales rep on the same latest date

 


Regards
Zubair

Please try my custom visuals

@Anonymous

 

Alternatively you could use this formula as well

As a MEASURE

 

LastSalesRep_ =
CALCULATE (
    CONCATENATEX (
        FILTER (
            TableName,
            TableName[Last order date] = MAX ( TableName[Last order date] )
        ),
        TableName[Sales Rep],
        ", "
    )
)

Regards
Zubair

Please try my custom visuals

@Anonymous

 

As a calculated column you could use

 

Column =
VAR MyMax =
    CALCULATE (
        MAX ( TableName[Last order date] ),
        ALLEXCEPT ( TableName, TableName[Customer #] )
    )
RETURN
    CALCULATE (
        FIRSTNONBLANK ( TableName[Sales Rep], 1 ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Customer #] ),
            TableName[Last order date] = MyMax
        )
    )

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

hi @Zubair_Muhammad

 

THe measures work perfectly but the column actually doesnt, It will always show only one person and thats i guess the sales person that placed the order last and is first in the alpabetical order.  

 

Only if I use the CONCATENATEX version i get the right result but then there are the other results behind it in case of same order date..

 

How can we modify the calculate column formlua that way that it will get the last sales rep per customer/account .. so what the measure does but as a column 

 

Thank you 

 

@Anonymous

 

7600.png


Regards
Zubair

Please try my custom visuals

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.