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

Calculated table with unique values

I have a calculated table with the following code, that I would like to get unique values from based on the earliest date for "Datum afspraak" (date appointment):

 

CALC NP's (Uniek) = SUMMARIZE('CALC NP''s (Niet uniek)', 
'CALC NP''s (Niet uniek)'[Patiëntnummer],
'CALC NP''s (Niet uniek)'[Geslacht],
'CALC NP''s (Niet uniek)'[Online geboekt], 
'CALC NP''s (Niet uniek)'[Datum afspraak],
'CALC NP''s (Niet uniek)'[Datum boeking],
'CALC NP''s (Niet uniek)'[Gebruiker],
'CALC NP''s (Niet uniek)'[Locatie])

 

The table currently looks like this:

Sohan_0-1639049746455.png

 

I only want the rows to show that contain the earliest "Datum afspraak". There should not be any duplicate values in the column "Patiëntnummer" .Does anyone know how I can achieve this?

 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Sohan , Try like

 

Filter(
ADDCOLUMNS( SUMMARIZE('CALC NP''s (Niet uniek)',
'CALC NP''s (Niet uniek)'[Patiëntnummer],
'CALC NP''s (Niet uniek)'[Geslacht],
'CALC NP''s (Niet uniek)'[Online geboekt],
'CALC NP''s (Niet uniek)'[Datum afspraak],
'CALC NP''s (Niet uniek)'[Datum boeking],
'CALC NP''s (Niet uniek)'[Gebruiker],
'CALC NP''s (Niet uniek)'[Locatie]
) , "_Min" , minx(filter('CALC NP''s (Niet uniek)', [Patiëntnummer] =earlier([Patiëntnummer])), 'CALC NP''s (Niet uniek)'[Datum afspraak])
)
_Min = [Datum afspraak] )

View solution in original post

Samarth_18
Community Champion
Community Champion

try this:-

calc =
FILTER (
    ADDCOLUMNS (
        SUMMARIZE (
            'CALC NP''s (Niet uniek)',
            'CALC NP''s (Niet uniek)'[Patiëntnummer],
            'CALC NP''s (Niet uniek)'[Geslacht],
            'CALC NP''s (Niet uniek)'[Online geboekt],
            'CALC NP''s (Niet uniek)'[Datum afspraak],
            'CALC NP''s (Niet uniek)'[Datum boeking],
            'CALC NP''s (Niet uniek)'[Gebruiker],
            'CALC NP''s (Niet uniek)'[Locatie]
        ),
        "_Min",
            MINX (
                FILTER (
                    'CALC NP''s (Niet uniek)',
                    [Patiëntnummer] = EARLIER ( [Patiëntnummer] )
                ),
                'CALC NP''s (Niet uniek)'[Datum afspraak]
            )
    ),
    [_Min] = [Datum afspraak]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@Sohan , Try like

 

Filter(
ADDCOLUMNS( SUMMARIZE('CALC NP''s (Niet uniek)',
'CALC NP''s (Niet uniek)'[Patiëntnummer],
'CALC NP''s (Niet uniek)'[Geslacht],
'CALC NP''s (Niet uniek)'[Online geboekt],
'CALC NP''s (Niet uniek)'[Datum afspraak],
'CALC NP''s (Niet uniek)'[Datum boeking],
'CALC NP''s (Niet uniek)'[Gebruiker],
'CALC NP''s (Niet uniek)'[Locatie]
) , "_Min" , minx(filter('CALC NP''s (Niet uniek)', [Patiëntnummer] =earlier([Patiëntnummer])), 'CALC NP''s (Niet uniek)'[Datum afspraak])
)
_Min = [Datum afspraak] )

@Sohan, I think  , was missing, as suggested by @Samarth_18 . Make sure table name before it. and min is column [_Min] 

new table =

Filter(
ADDCOLUMNS( SUMMARIZE('CALC NP''s (Niet uniek)',
'CALC NP''s (Niet uniek)'[Patiëntnummer],
'CALC NP''s (Niet uniek)'[Geslacht],
'CALC NP''s (Niet uniek)'[Online geboekt],
'CALC NP''s (Niet uniek)'[Datum afspraak],
'CALC NP''s (Niet uniek)'[Datum boeking],
'CALC NP''s (Niet uniek)'[Gebruiker],
'CALC NP''s (Niet uniek)'[Locatie]
) , "_Min" , minx(filter('CALC NP''s (Niet uniek)', [Patiëntnummer] =earlier([Patiëntnummer])), 'CALC NP''s (Niet uniek)'[Datum afspraak])
) ,
[_Min] = [Datum afspraak] )

Thanks for your response @amitchandak! It says the syntax is incorrect for "_Min = [Datum afspraak]". Any idea what I should change?

 

Sohan_0-1639050979086.png

 

 

Samarth_18
Community Champion
Community Champion

Hi @Sohan ,

There is one comma missing in the code. Below is updated code:-

FILTER (
    ADDCOLUMNS (
        SUMMARIZE (
            'CALC NP''s (Niet uniek)',
            'CALC NP''s (Niet uniek)'[Patiëntnummer],
            'CALC NP''s (Niet uniek)'[Geslacht],
            'CALC NP''s (Niet uniek)'[Online geboekt],
            'CALC NP''s (Niet uniek)'[Datum afspraak],
            'CALC NP''s (Niet uniek)'[Datum boeking],
            'CALC NP''s (Niet uniek)'[Gebruiker],
            'CALC NP''s (Niet uniek)'[Locatie]
        ),
        "_Min",
            MINX (
                FILTER (
                    'CALC NP''s (Niet uniek)',
                    [Patiëntnummer] = EARLIER ( [Patiëntnummer] )
                ),
                'CALC NP''s (Niet uniek)'[Datum afspraak]
            )
    ),
    _Min = [Datum afspraak]
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 Thank you for your reply! When I change "_Min =" to "[_Min] =" it works! I now however get the following message: 

Column '' in Table '' contains a duplicate value '457-3773' and this is not allowed for columns on the one side of a many-to-one relationship or for columns that are used as the primary key of a table.

 

Any idea how I can get the desired result?

Samarth_18
Community Champion
Community Champion

try this:-

calc =
FILTER (
    ADDCOLUMNS (
        SUMMARIZE (
            'CALC NP''s (Niet uniek)',
            'CALC NP''s (Niet uniek)'[Patiëntnummer],
            'CALC NP''s (Niet uniek)'[Geslacht],
            'CALC NP''s (Niet uniek)'[Online geboekt],
            'CALC NP''s (Niet uniek)'[Datum afspraak],
            'CALC NP''s (Niet uniek)'[Datum boeking],
            'CALC NP''s (Niet uniek)'[Gebruiker],
            'CALC NP''s (Niet uniek)'[Locatie]
        ),
        "_Min",
            MINX (
                FILTER (
                    'CALC NP''s (Niet uniek)',
                    [Patiëntnummer] = EARLIER ( [Patiëntnummer] )
                ),
                'CALC NP''s (Niet uniek)'[Datum afspraak]
            )
    ),
    [_Min] = [Datum afspraak]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 Thanks! Please see my previous reply 😊

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.