cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pwagma
Helper I
Helper I

Show only the first record with a condition in a gallery. Distinct function? Not sure

Hello

I have a CDS database with all my customers. Inside this database, I have multiple records with each customer because there is one record per address per customer.

Long story short, I only want to show one record per customer. I don't care which record it is. I am a bit lost with this...

The column it is called "idcliente" and I would like to show only 1 record per "idcliente". First I was filtering using the 1st adress... but some customers don't have the "1st adress" and start in adress number 2 or 3, so it doesn't work anymore...

 

This is my actual code, where I need to add this condition.

 

SortByColumns(AddColumns(SortByColumns(Filter(Clientes,(DropdownEstadoClientes.Selected.Value = "Todos los estados" || NombreEstado = DropdownEstadoClientes.Selected.Value), !(NombreEstado="ANULADOS"),!(NombreEstado = "ANALIZADO BAJA"), NombreVendedor = VarVendedores, TextSearchBox1_2.Text in NombreCliente),"createdon",Descending),"nuevoid",Value(cr398_idcliente)),"nuevoid", If(SortDescending1, Ascending, Descending))

 

THanks

Pablo

1 ACCEPTED SOLUTION

Accepted Solutions
v-albai-msft
Community Support
Community Support

Hi @pwagma,

Do you mean that "each customer has more than one records with different addresses, but you just want to display one record for each customer(no matter other values)"?

Also, does "idcliente" column contain the customer name?

If yes, I assume you have a CDS database like below with 7 records, and you want to display 3 records of different 3 customers in your gallery.

v-albai-msft_0-1614241955570.png

So I use this formula in my gallery:

ForAll(Distinct(Clientes,idcliente),First(Filter(Clientes,idcliente=Result)))

See results below the gallery display only three records for three customers. You can then add other action or conditions based on below data:

v-albai-msft_1-1614241955575.png

Best Regards,

Allen

View solution in original post

4 REPLIES 4
Drrickryp
Super User
Super User

@pwagma 

You can use Lookup() to find the first record that matches a condition.

But I don't need it to match a condition, it is for a gallery, it has to list it

v-albai-msft
Community Support
Community Support

Hi @pwagma,

Do you mean that "each customer has more than one records with different addresses, but you just want to display one record for each customer(no matter other values)"?

Also, does "idcliente" column contain the customer name?

If yes, I assume you have a CDS database like below with 7 records, and you want to display 3 records of different 3 customers in your gallery.

v-albai-msft_0-1614241955570.png

So I use this formula in my gallery:

ForAll(Distinct(Clientes,idcliente),First(Filter(Clientes,idcliente=Result)))

See results below the gallery display only three records for three customers. You can then add other action or conditions based on below data:

v-albai-msft_1-1614241955575.png

Best Regards,

Allen

View solution in original post

pwagma
Helper I
Helper I

Hello   

Finally, I used other solution, I add a column directly on the CDS, called "main", and the 1st one of each is "1" and the rest is "0", so I just add a filter main = 1, easy.

Anyways, using code, is exactly what I was looking for, and I will save it for future use.

Thanks for the detailed explanation.

Thank you

Pablo

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,838)