web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details
Power Apps - Building Power Apps
Answered

How to count and group by month and year from SharePoint list and create a collection to use in a chart?

Like (0) ShareShare
ReportReport
Posted on 4 Aug 2021 13:50:54 by 514

I want to use the chart facility in PowerApps.

 

I would like to show the months of the year and a total of completed items in each month.

 

My SharePoint list has columns for CompletedDate, CompletedDateMonth, CompletedDateYear

I am unsure if I need to create a months collection with the data and then base the chart on this data source.

Is there a way of grouping and counting and mapping the month name to a month name in the collection?

 

Jan Feb March

2     3      7

 

etc


Any example appreciated

 

Thanks

 

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,289 Super User 2024 Season 1 on 04 Aug 2021 at 14:03:51
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    @sienna28 

    You will not need any collections to do this, but I would need more detail on what kind of graph you are aiming for.

    What is it that you want to display in a chart?  What is the series and axis values and how do you want to display it?

  • sienna28 Profile Picture
    514 on 04 Aug 2021 at 14:11:19
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    Thanks for replying

    I am looking at a standard bar chart.

     

    The horizontal axis will list the month names.

     

    Hoping then that the bars will show for the count in each month for the completed dates.

    So for example if I have data for these completed dates in January..

    28/01/2021

    11/01/2021

    17/01/2021

     

    The January bar would show a count of 3

     

    Thanks

  • RandyHayes Profile Picture
    76,289 Super User 2024 Season 1 on 04 Aug 2021 at 14:21:23
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    @sienna28 

    Very good.  Now a couple more questions:

    1) What about the months that do not have data?  Or in other words, do you want your bar chart to have all 12 months in it and then show counts for each month, or only to have the months that have data shown?

    2) Will your chart encompass only the current year?

    3) What will happen (or is expected to be displayed/or not) for records that have No Due Date?

  • sienna28 Profile Picture
    514 on 04 Aug 2021 at 14:38:01
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    Thanks for the reply.

    Yes I was wondering about this also.
    I would prefer to show all months - Jan to Dec in the chart.

    Ideally a zero would be displayed for months with no count data.

    If that was not possible, then I guess it would only show the months that actually contain data.

    Ideally it would be nice to be able to feed in a year and display the relevant info, but if too complex to do this then I guess it could work on the current year.
    For records with no completed date then they would be counted as zero

  • RandyHayes Profile Picture
    76,289 Super User 2024 Season 1 on 04 Aug 2021 at 15:03:25
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    @sienna28 

    Nope, not too complex at all, but getting the requirements is key to providing the solution.

     

    Your Items property for your ColumnChart should be:

    With({_year: 2021},
     With({_items: 
     AddColumns(
     Filter(yourDataSource, OrderCompletedDate >= Date(_year, 1, 1) && OrderCompletedDate<= Date(_year,12, 31)),
     "_month", Month(OrderCompletedDate)
     )
     },
    
     ForAll(Sequence(12),
     {_month: Last(FirstN(Calendar.MonthsShort(), Value).Value,
     _count: CountRows(Filter(_items, _month=Value))
     }
     )
     )
    )
     

    Replace the name of the data source to yours. 

    Set your Labels property of the chart to : _month and the Series1 property to : _count

    and you will then have your chart.

     

    If you want to add some sort of option for selecting a year, you could consider a dropdown (let's call it ddYear) with an Items property of :  ForAll(Sequence(3, 0), Year(Today())-Value)

    This would give you the current and past two years in the dropdown.

    You can then replace the hard-written 2021 in the formula with ddYear.Selected.Value

     

    Note that the above does not use the Year and Month columns you already have in the data list as they are not needed and can derive from the OrderCompletedDate itself.  However, adding the variable year span in the formula will provide delegation warnings.  If your datasource is less than 2000 items (and not expected to go beyond) then you can ignore the warning.  If it is, then you can adjust the formula to utilize the Year that you already have in the record instead.

     

  • sienna28 Profile Picture
    514 on 04 Aug 2021 at 15:37:02
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    Thank you very much for helping.

     

    I've pasted the code in and it mostly seems fine except the series and labels boxes are greyed out and won't allow me to select anything

  • RandyHayes Profile Picture
    76,289 Super User 2024 Season 1 on 04 Aug 2021 at 15:54:31
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    @sienna28 

    Post back your entire Items property formula so that I can verify it.

  • sienna28 Profile Picture
    514 on 04 Aug 2021 at 15:59:52
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    Here it is...thanks

    With({_year: 2021},
    With({_items:
    AddColumns(
    Filter(AutoWork, OrderCompleteDate >= Date(_year, 1, 1) && OrderCompleteDate<= Date(_year,12, 31)),
    "_month", Month(OrderCompleteDate)
    )
    },

    ForAll(Sequence(12),
    {_month: Last(FirstN(Calendar.MonthsShort(), Value).Value),
    _count: CountRows(Filter(_items, _month=Value))
    }
    )
    )
    )

  • RandyHayes Profile Picture
    76,289 Super User 2024 Season 1 on 04 Aug 2021 at 16:04:19
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    @sienna28 

    It's having a delegation struggle and as such will not let you change the labels and series.

    Let's make the following change:

    For the dropdown, set the Items property to:

    ForAll(Sequence(3, 0), 
     With({_yr: Year(Today())-Value}, 
     {Value:_yr, 
     Start: Date(_yr,1,1), 
     End:Date(_yr, 12,31)
     }
     )
    )

    This will provide a valid start and end date for the filter.

    Then change the Items property or the chart to the following:

    With({_items:
     AddColumns(
     Filter(AutoWork, OrderCompleteDate >= ddYear.Selected.Start && 
     OrderCompleteDate<= ddYear.Selected.End
     ),
     "_month", Month(OrderCompleteDate)
     )
     },
    
     ForAll(Sequence(12),
     {_month: Last(FirstN(Calendar.MonthsShort(), Value).Value),
     _count: CountRows(Filter(_items, _month=Value))
     }
     )
    )

    This will remove the delegation confusion it is having and you should be able to select the label and series at that point.

  • sienna28 Profile Picture
    514 on 04 Aug 2021 at 16:29:38
    Re: How to count and group by month and year from SharePoint list and create a collection to use in a chart?

    Thanks - seems a bit better, but all the labels and series seem to only have count available to select and not month.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 752 Most Valuable Professional

#2
developerAJ Profile Picture

developerAJ 472

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 358 Super User 2025 Season 2

Last 30 days Overall leaderboard