cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DarylMcC
Level: Powered On

CountRows If using Distinct on a different column

Hi All,

 

I'm currently trying to count rows between a certain date and only once per person from a SharePoint list.

I have it working for counting between the dates :

CountRows((Filter(WorkFromHome,Value(Text('DateUsed',"[$-en-US]yyyymmdd"))>=Value(Text(DateAdd(Today(),-30),"[$-en-US]yyyy-mm-dd")))))

 

I also have one working with only rows with a unique name:

 

CountRows(Distinct(WorkFromHome.Name,Name))

 

I know I need to combine the two somehow but I'm Stuck after a few hours. 

 

Any help at all would be much appreciated !

 

Thanks!

 

5 REPLIES 5
Super User
Super User

Re: CountRows If using Distinct on a different column

@DarylMcC 

My idea is to 1st collect the Distinct Names and then make a 2nd collection where we add a column to show the count.

 

ClearCollect(
    myUniqueNames,
    Distinct(WorkFromHome.Name,Name) // produces a single column called Result
);
ClearCollect(
    myCountByName,
    AddColumns(
        myUniqueNames,
        "myCount",
        CountRows(
            Filter(
                WorkFromHome,
                Name = myUniqueNames[@Result],
                Value(Text('DateUsed',"[$-en-US]yyyymmdd"))>=Value(Text(DateAdd(Today(),-30),"[$-en-US]yyyy-mm-dd"))
        )
    )
);

 

This was the key piece of code added to the 2nd collection

 

Name = myUniqueNames[@Result]

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

DarylMcC
Level: Powered On

Re: CountRows If using Distinct on a different column

Hi @mdevaney ,

 

Thank you for your help!

 

I'm Currently getting this error when I attempt to use your solution:

 

Do you know how I can resolve this?

 

Thank you again for your help!

 

 

image.png

Super User
Super User

Re: CountRows If using Distinct on a different column

@DarylMcC 

Its just a syntax error.  Please change this line...

\\ produces a single column called Result

 

...into this code.

// produces a single column called Result

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

DarylMcC
Level: Powered On

Re: CountRows If using Distinct on a different column

@mdevaney 

Still not working, it seems like there's an issue with the name of the collection, do i need to put it into the "OnStart" of the app maybe?

 

image.png

Super User
Super User

Re: CountRows If using Distinct on a different column

@DarylMcC 

Suggest you try to get this small part working first.  Then add the 2nd part.

ClearCollect(
    myUniqueNames,
    Distinct(WorkFromHome.Name,Name)
);

 

(Also, I can't see part of the text on your screen because the error message is in the way, lol)

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (4,153)