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
Sohan
Helper III
Helper III

Get distinct values in calculated table

I have the following calculated table:

 

Client IDEmployee nameDate appointment
1Employee X5-1-2021
1Employee Y7-1-2021

 

I only want the first row to show. I only want the client ID to appear once, with the earliest date. How can I do this?

2 ACCEPTED SOLUTIONS
selimovd
Super User
Super User

Hey @Sohan ,

 

if you want to get only the earliest date, the following measure should do the job:

 

First Date by client =
CALCULATE(
    MIN( myTable[Date appointment] ),
    ALLEXCEPT(
        myTable,
        myTable[Client ID]
    )
)

 

 

If you only want to show the first row, you also have to replace the employee column with the following measure:

First Employee = 
VAR vFirstDate = [First Date by client]
RETURN
CALCULATE(
    MIN( myTable[Employee name] ),
    ALLEXCEPT(
        myTable,
        myTable[Client ID]
    ),
    myTable[Date appointment] = vFirstDate
)

 

Then you should put the two measures in a table and you get the result you want:

selimovd_0-1626256545774.png

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

View solution in original post

Hi @Sohan ,

 

You can create a visual level filter:

 

Measure = IF(MAX('Table'[Date appointment]) = CALCULATE(MIN('Table'[Date appointment]),ALLEXCEPT('Table','Table'[Client ID])),1,0)

 

Capture8.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

11 REPLIES 11
selimovd
Super User
Super User

Hey @Sohan ,

 

if you want to get only the earliest date, the following measure should do the job:

 

First Date by client =
CALCULATE(
    MIN( myTable[Date appointment] ),
    ALLEXCEPT(
        myTable,
        myTable[Client ID]
    )
)

 

 

If you only want to show the first row, you also have to replace the employee column with the following measure:

First Employee = 
VAR vFirstDate = [First Date by client]
RETURN
CALCULATE(
    MIN( myTable[Employee name] ),
    ALLEXCEPT(
        myTable,
        myTable[Client ID]
    ),
    myTable[Date appointment] = vFirstDate
)

 

Then you should put the two measures in a table and you get the result you want:

selimovd_0-1626256545774.png

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

@selimovd I did something wrong. Your code works like a charm. Thank you so much for your help!

Hi @selimovd, thanks for your response! The measure does not seem to give the desired result. This is the table I'm getting with it:

Sohan_0-1626256617014.png

I want the table above (in the post), with all columns.

Hey @Sohan ,

 

you also have to add the Client ID column and then the First Employee measure to your table.

If you just put the first date measure you will only see the first date overall.

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

@selimovd of course, thanks! I do get the unique client ID now, but I only get the very first date (5-1-2021) and first employee (employee x) for all rows. Even when this isn't correct in the data.

Hey @Sohan ,

 

can you share a screenshot of the result?

I think that's easier than the description.

 

Best regards

Denis

Hi @selimovd, please find the screenshot here:

 

Sohan_0-1626272066130.png

 

Hi @Sohan ,

 

You can create a visual level filter:

 

Measure = IF(MAX('Table'[Date appointment]) = CALCULATE(MIN('Table'[Date appointment]),ALLEXCEPT('Table','Table'[Client ID])),1,0)

 

Capture8.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

@Sohan did you put your Client ID column in the table?

If you use the Client ID from the table and the 2 measures it should work:

selimovd_0-1626273360642.png

 

Best regards

Denis

@selimovd the first column is the client ID.

@Sohan then in your file there is something different from my example file 😏

Can you share the file? Like this, I could take a look directly into your case. Maybe you could remove or replace sensitive data.

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.