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 II
Super User II

@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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (2,486)