Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

null

null

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1664256529386.png

Here are the steps you can follow:

1. Create calculated table.

Table 2 =
DISTINCT('Table'[Fiscal Month])

vyangliumsft_1-1664256529392.png

2. Create measure.

Flag =
VAR _count =
    COUNTX ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Fiscal Month] )
VAR _select =
    SELECTCOLUMNS ( 'Table 2', "1", [Fiscal Month] )
VAR _min =
    MINX ( FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ), [Date] )
VAR _minID =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Date] ) = YEAR ( _min )
                && MONTH ( 'Table'[Date] )
                    = MONTH ( _min ) - 1
        ),
        [Fiscal Month ID]
    )
VAR _max =
    MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ), [Date] )
VAR _maxdate =
    DATE ( YEAR ( _max ), MONTH ( _max ), 1 )
VAR _secondID =
    MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] < _maxdate ), [Fiscal Month ID] )
VAR _allsum1 =
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ),
        [Ending HC]
    )
        + SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month ID] = _minID ),
            [Ending HC]
        )
VAR _if1 =
    DIVIDE ( _allsum1, _count + 1 )
VAR _allsum2 =
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ),
        [Ending HC]
    )
        + SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month ID] = _minID ),
            [Ending HC]
        )
        + SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month ID] = _secondID ),
            [Ending HC]
        )
VAR _if2 =
    DIVIDE ( _allsum2, _count * 2 )
RETURN
    IF ( _count = 1, _if1, _if2 )

3. Result:

vyangliumsft_2-1664256529397.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @Anonymous ,

I created some data:

vyangliumsft_0-1664256529386.png

Here are the steps you can follow:

1. Create calculated table.

Table 2 =
DISTINCT('Table'[Fiscal Month])

vyangliumsft_1-1664256529392.png

2. Create measure.

Flag =
VAR _count =
    COUNTX ( ALLSELECTED ( 'Table 2' ), 'Table 2'[Fiscal Month] )
VAR _select =
    SELECTCOLUMNS ( 'Table 2', "1", [Fiscal Month] )
VAR _min =
    MINX ( FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ), [Date] )
VAR _minID =
    MAXX (
        FILTER (
            ALL ( 'Table' ),
            YEAR ( 'Table'[Date] ) = YEAR ( _min )
                && MONTH ( 'Table'[Date] )
                    = MONTH ( _min ) - 1
        ),
        [Fiscal Month ID]
    )
VAR _max =
    MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ), [Date] )
VAR _maxdate =
    DATE ( YEAR ( _max ), MONTH ( _max ), 1 )
VAR _secondID =
    MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Date] < _maxdate ), [Fiscal Month ID] )
VAR _allsum1 =
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ),
        [Ending HC]
    )
        + SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month ID] = _minID ),
            [Ending HC]
        )
VAR _if1 =
    DIVIDE ( _allsum1, _count + 1 )
VAR _allsum2 =
    SUMX (
        FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month] IN _select ),
        [Ending HC]
    )
        + SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month ID] = _minID ),
            [Ending HC]
        )
        + SUMX (
            FILTER ( ALL ( 'Table' ), 'Table'[Fiscal Month ID] = _secondID ),
            [Ending HC]
        )
VAR _if2 =
    DIVIDE ( _allsum2, _count * 2 )
RETURN
    IF ( _count = 1, _if1, _if2 )

3. Result:

vyangliumsft_2-1664256529397.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Anonymous
Not applicable

Do you have an alternative without creating a table ?

jgeddes
Super User
Super User

Try

Average Headcount =
var _lowHC =
min(fiscalMonthHC[Fiscal Month ID])-1
var _highHC =
max(fiscalMonthHC[Fiscal Month ID])
Return
averagex(
    filter(all(fiscalMonthHC), fiscalMonthHC[Fiscal Month ID] >= _lowHC && fiscalMonthHC[Fiscal Month ID] <= _highHC),
    [Ending HC]
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.