web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / AddColumns, Groupby Da...
Power Apps
Answered

AddColumns, Groupby Data to send an attachment

(0) ShareShare
ReportReport
Posted on by 14

Can anyone please optimize the below code, at present, the code working perfectly.

I want this data to be sent as an attachment by using Power Automate. Looking for help.

//Code Begin

Sort(
AddColumns(
GroupBy(Filter(Chronicles,TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate),
"TaskDate",
"ByDate"
),
"TOT",
Sum(
Filter(
ByDate,
TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"BAH",
Sum(
Filter(
ByDate,
Country = "Bahrain" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"KSA",
Sum(
Filter(
ByDate,
Country = "Saudi Arabia" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"QAT",
Sum(
Filter(
ByDate,
Country = "Qatar" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"OMN",
Sum(
Filter(
ByDate,
Country = "Oman" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"DXB",
Sum(
Filter(
ByDate,
Country = "Dubai" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"ABD",
Sum(
Filter(
ByDate,
Country = "Abu Dhabi" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"SD",
Sum(
Filter(
ByDate,
Country = "Stevedoring" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
),
"REG",
Sum(
Filter(
ByDate,
Country = "Regional" && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
),
TaskDuration
)
),
TaskDate,
SortOrder.Ascending
)

//Code End

 

//The Screen

JohnHenry_0-1698563385909.png

 

Categories:
I have the same question (0)
  • Verified answer
    AhmedSalih Profile Picture
    6,680 Moderator on at

    Hello, @JohnHenry, there is so much redundancy:

    ClearCollect(
     ProcessedData,
     Sort(
     AddColumns(
     GroupBy(
     Filter(
     Chronicles,
     TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
     ),
     "TaskDate",
     "AllData"
     ),
     "Data", 
     ForAll(
     [
     "Bahrain", 
     "Saudi Arabia", 
     "Qatar", 
     "Oman", 
     "Dubai", 
     "Abu Dhabi", 
     "Stevedoring", 
     "Regional"
     ],
     Sum(
     Filter(
     AllData,
     Country = CurrentRecord && TaskDate >= FilterStartDate_1.SelectedDate && TaskDate <= FilterEndDate_1.SelectedDate
     ),
     TaskDuration
     )
     ),
     "TOT", Sum(AllData, TaskDuration)
     ),
     TaskDate,
     SortOrder.Ascending
     )
    );
    

     Send the Data as JSON:

    Set(
     JsonData,
     JSON(ProcessedData, JSONFormat.IncludeBinaryData)
    );
    
    PowerAutomateFlowName.Run(JsonData)

     


    If my reply helped you, please give a 👍 If it solved your issue, please give a 👍 & accept it as the Solution to help other community members find it more.

    Visit my Blog: ahmedsalih.blog

    Visit my YouTube Channel: https://www.youtube.com/@powerplatformplace/videos

    Microsoft Business Application MVP

  • JohnHenry Profile Picture
    14 on at

    Thank you So much Mr. Ahmed.

    It shows error when I copy this code in "Items Property".

    Do I need change any column name or source name. please help.

  • AhmedSalih Profile Picture
    6,680 Moderator on at

    @JohnHenry, What was the error? Can you share screenshot?

  • JohnHenry Profile Picture
    14 on at

    JohnHenry_0-1698584264271.png

    "The function 'ClearCollect' has some invalid arguments.

    Name is not valid. 'ProcessedData' isn't recognized.

  • AhmedSalih Profile Picture
    6,680 Moderator on at

    @JohnHenry, ClearCollect can't be in the Items property of a Gallery, use the Code in the Screen.OnVisible. To test add a Button and use it for the Collection creation.

     


    If my reply helped you, please give a 👍 If it solved your issue, please give a 👍 & accept it as the Solution to help other community members find it more.

    Visit my Blog: ahmedsalih.blog

    Visit my YouTube Channel: https://www.youtube.com/@powerplatformplace/videos

    Microsoft Business Application MVP

  • JohnHenry Profile Picture
    14 on at

    john.henry@sarensnass.com

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 150 Super User 2026 Season 2

Last 30 days Overall leaderboard