Forum Discussion

El_Bastien's avatar
El_Bastien
Frequent Visitor
1 year ago

Line Graph Aggregate instead of Average

Hi, I'm having issues with a visual. I want the average headcount by employee type by a quarter displayed on a line graph. This is the formula I have to get the average.

 

Avg Headcount = 
    AVERAGEX(
        VALUES('FY25'[Employee Type]),
        CALCULATE(SUM('FY25'[Count]))
    )

 
When adding that to the line graph it displays this.

 

The line graph format is the one I'm looking for, showing each quarter by month. However, the values do not give the average but the aggregation. Any ideas on how to do this?

 

To give you some extra details, these are the Tables and Columns I'm using

Table 1
- Employee Name

- Employee Type

- Count (Just a 1 assigned to each column)
- Period (Month Starting Date)

Calendar

Calendar = 

--Inputs--
VAR WeekStartsOn = "Mon"
VAR FiscalStartMonth = 7 

--NOTE: Calendar week starts from Monday

--Calculation--
RETURN
    ADDCOLUMNS (
        CALENDARAUTO ( FiscalStartMonth - 1 ),
        "MIndex", MONTH ( [Date] ),
        "FiscalMIndex", MONTH ( EDATE ( [Date], - FiscalStartMonth + 1 ) ),
        "CalMonth", FORMAT ( [Date], "mmm" ),
        "CalQtr", "Q"
            & CEILING ( MONTH ( [Date] ), FiscalStartMonth - 1 ) / ( FiscalStartMonth - 1 ),
        "CalYear", YEAR ( [Date] ),
        "Fiscal Week",
        VAR FiscalFirstDay =
            IF (
                MONTH ( [Date] ) < FiscalStartMonth,
                DATE ( YEAR ( [Date] ) - 1, FiscalStartMonth, 1 ),
                DATE ( YEAR ( [Date] ), FiscalStartMonth, 1 )
            )
        VAR FilteredTableCount =
            COUNTROWS (
                FILTER (
                    SELECTCOLUMNS ( GENERATESERIES ( FiscalFirstDay, [Date] ), "Dates", [Value] ),
                    FORMAT ( [Dates], "ddd" ) = WeekStartsOn
                )
            )
        VAR WeekNos =
            IF (
                FORMAT ( FiscalFirstDay, "ddd" ) <> WeekStartsOn,
                FilteredTableCount + 1,
                FilteredTableCount
            )
        RETURN
            "Week " & WeekNos,
        "Fiscal Qtr", "Q"
            & CEILING ( MONTH ( EDATE ( [Date], - FiscalStartMonth + 1 ) ), 3 ) / 3,
        "Fiscal Year",
        VAR CY =
            RIGHT ( YEAR ( [Date] ), 2 )
        VAR NY =
            RIGHT ( YEAR ( [Date] ) + 1, 2 )
        VAR PY =
            RIGHT ( YEAR ( [Date] ) - 1, 2 )
        VAR FinYear =
            IF ( MONTH ( [Date] ) > ( FiscalStartMonth - 1 ), NY , CY )
        RETURN
            FinYear,
        "CalWeekNo", WEEKNUM ( [Date], 2 ),
        "Weekend/Working", IF ( WEEKDAY ( [Date], 2 ) > 5, "Weekend", "Working" ),
        "Day", FORMAT ( [Date], "ddd" )
    )

 
Thanks in advance for the help!

2 Replies

    • El_Bastien's avatar
      El_Bastien
      Frequent Visitor
      EmployeeCategoryMonthPeriodCount
      904GTApril01/04/241
      54AApril01/04/241
      363CMay01/05/241
      1DMay01/05/241
      54AMay01/05/241
      591CJune01/06/241
      1DJune01/06/241
      54AJune01/06/241
      489CJuly01/07/241
      1DJuly01/07/241
      54AJuly01/07/241
      591CAugust01/08/241
      1DAugust01/08/241
      54AAugust01/08/241
      591CSeptember01/09/241
      1DSeptember01/09/241
      244DSeptember 01/09/241
      54ASeptember01/09/241
      1DOctober01/10/241
      54AOctober01/10/241

       

      Here is the sample data.

       

      Ignore the "Employee" column as it is unimportant to the problem.

       

      The expected outputs are:

      Average Quarterly Headcount by Category. In my first message, I inserted a picture of what the line chart has to be like. The problem with that is that PBI aggregates each quarter, and I need the average. for example if: M1=100, M2=105, M3=110, the Q1avg = 105. The average must be shown when displaying the year and the quarter (as shown in the picture). If necessary, we can add the month as the lowest level, but that is optional.

      Thank you so much! Anonymous