Hello Power Apps Community,
I'm seeking assistance to create a line chart in Power Apps that plots two lines. The first line should display the top 3 HSE Observation Categories for the current month, and the second line should display the top 3 categories for the previous month.
I have slightly modified the App OnStart code (originally assisted by and modified by @WarrenBelz ) for a previous task to generate the top 3 observers, using similar logic to include the top 3 trending categories. Here is the code:
With(
{
_AllObservations: 'HSE Observations - KPO',
_StartThisMonth: Date(Year(Today()), Month(Today()), 1),
_EndThisMonth: DateAdd(Date(Year(Today()), Month(Today()), 1), 1, TimeUnit.Months) - 1,
_StartPrevMonth: DateAdd(Date(Year(Today())), Month(Today()), 1), -1, TimeUnit.Months),
_EndPrevMonth: Date(Year(Today()), Month(Today()), 1) - 1
},
With(
{
_CurrentMonthObservations: Filter(_AllObservations, DateValue(DateTime) >= _StartThisMonth && DateValue(DateTime) <= _EndThisMonth),
_PreviousMonthObservations: Filter(_AllObservations, DateValue(DateTime) >= _StartPrevMonth && DateValue(DateTime) <= _EndPrevMonth)
},
With(
{
_TopCurrentMonthObservers: FirstN(
Sort(
AddColumns(
GroupBy(
AddColumns(_CurrentMonthObservations, ObserverName, Observer.DisplayName),
ObserverName, ObserverGroup
),
ObservationCount, CountRows(ObserverGroup)
),
ObservationCount, SortOrder.Descending
),
3
),
_TopPreviousMonthObservers: FirstN(
Sort(
AddColumns(
GroupBy(
AddColumns(_PreviousMonthObservations, ObserverName, Observer.DisplayName),
ObserverName, ObserverGroup
),
ObservationCount, CountRows(ObserverGroup)
),
ObservationCount, SortOrder.Descending
),
3
),
_TopCurrentMonthCategories: FirstN(
Sort(
AddColumns(
GroupBy(
AddColumns(_CurrentMonthObservations, CategoryName, ObservationType.Value),
CategoryName, CategoryGroup
),
CategoryCount, CountRows(CategoryGroup)
),
CategoryCount, SortOrder.Descending
),
3
),
_TopPreviousMonthCategories: FirstN(
Sort(
AddColumns(
GroupBy(
AddColumns(_PreviousMonthObservations, CategoryName, ObservationType.Value),
CategoryName, CategoryGroup
),
CategoryCount, CountRows(CategoryGroup)
),
CategoryCount, SortOrder.Descending
),
3
)
},
ClearCollect(TopCurrentMonthObservers, _TopCurrentMonthObservers);
ClearCollect(TopPreviousMonthObservers, _TopPreviousMonthObservers);
ClearCollect(
CombinedCategories,
AddColumns(
_TopCurrentMonthCategories,
Month, "Current"
)
);
Collect(
CombinedCategories,
AddColumns(
_TopPreviousMonthCategories,
Month, "Previous"
)
)
)
)
)
The code works fine, but when I insert the line chart, I struggle to plot two separate lines. Instead, the chart displays one line with 3 categories for the current month and 3 for the previous month on the same line.
Is there any way to have Power Apps plot two separate lines on the same chart? Any help or guidance would be greatly appreciated!
Thank you in advance for your assistance.

Report
All responses (
Answers (