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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Need help with DAX

Hi,

 

I'm trying to write a DAX query for weekly rolling avg per emp, however, I'm unable to get the desired results in my report.

I've got Week_Key, Date_Key, Emp_ID, ActualWorkingHours, Avg_Hours.

I need help with getting a weekly rolling Avg per emp. Below is sample of the data and the outcome is mentioned as "Rolling Avg Working Time per week":

EmpIDweek_KeyWorking hours on that weekAbsence hours on that weekFixed working time, from Maconomy timecardCount of week (1 if no absences)Rolling Average working time per week
11300301.0030.00
1237.57.537.50.8037.50
1340037.51.0038.39
1430037.51.0036.18
150037.51.0028.65
1637.5037.51.0030.17
1737.5037.51.0031.25
28037.537.50.000.00
21060037.51.0060.00
21170037.51.0065.00
21237.5037.51.0055.83
21339037.51.0051.63
214340301.0048.10

 

Any help on this would be appreciated!!!

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

I read your requirements and I do some changes with my DAX code.

Column =
VAR _A =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[EmpID] = EARLIER ( 'Table'[EmpID] )
                && 'Table'[week_Key] <= EARLIER ( 'Table'[week_Key] )
        ),
        'Table'[Working hours on that week]
    )
        / SUMX (
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[EmpID] = EARLIER ( 'Table'[EmpID] )
                    && 'Table'[week_Key] <= EARLIER ( 'Table'[week_Key] )
            ),
            'Table'[Count of week (1 if no absences)]
        )
RETURN
    IF ( 'Table'[Count of week (1 if no absences)] = 0, 0, _A )

Then you will get what you want.

vyilongmsft_0-1711011997296.png

 

 

 

Best Regards

Yilong Zhou

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

6 REPLIES 6
Anonymous
Not applicable

Hi @Anonymous ,

Based on your problems, here are my answers.

write a DAX query for weekly rolling average per employee.

Rolling Avg Working Time per week =
VAR CurrentEmpID =
    MAX ( 'Table'[EmpID] )
VAR CurrentWeekKey =
    MAX ( 'Table'[week_Key] )
VAR PreviousWeeks =
    FILTER (
        ALLSELECTED ( 'Table' ),
        'Table'[EmpID] = CurrentEmpID
            && 'Table'[week_Key] <= CurrentWeekKey
    )
VAR Result =
    AVERAGEX ( PreviousWeeks, 'Table'[Working hours on that week] )
RETURN
    Result

Then I get the result.

vyilongmsft_0-1709709343216.png

But I don't get the result you need, can you give me the specific Rolling Average working time per week calculation process or give me the corresponding .pbix file?

 

 

 

How to Get Your Question Answered Quickly 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

Best Regards

Yilong Zhou

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

Anonymous
Not applicable

Hi @Anonymous ,

I'm unable to share the .pbix as there're certain restrictions for file sharing in my org.


This solution isn't working for me as I have got the information in three different tables namely "DimDate",  "DimEmployee" and "FactProjectHours".

The fields that I'm considering for this requirement are:

TableName  FieldName
DimEmployee  EmpID
DimEmployee  EmpName
DimEmployee  FixedHours per Week
DimDate  YearKey
DimDate  WeekKey
FactProjectHours  WorkingHours on the given Week
FactProjectHours  AbsenceHouse


WeekCount ( (FixedHours Per Week - AbsenceHouse) / FixedHours Per Week) ----- This is a measure to count the week as shown in the previous data sample table.


Please refer to the below screenshot for the expected result of rolling avg which is calculated in Excel.

Maheshguptaz_0-1709895822663.png

 






Anonymous
Not applicable

Hi @Anonymous ,

I read your requirements and I do some changes with my DAX code.

Column =
VAR _A =
    SUMX (
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[EmpID] = EARLIER ( 'Table'[EmpID] )
                && 'Table'[week_Key] <= EARLIER ( 'Table'[week_Key] )
        ),
        'Table'[Working hours on that week]
    )
        / SUMX (
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[EmpID] = EARLIER ( 'Table'[EmpID] )
                    && 'Table'[week_Key] <= EARLIER ( 'Table'[week_Key] )
            ),
            'Table'[Count of week (1 if no absences)]
        )
RETURN
    IF ( 'Table'[Count of week (1 if no absences)] = 0, 0, _A )

Then you will get what you want.

vyilongmsft_0-1711011997296.png

 

 

 

Best Regards

Yilong Zhou

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

Anonymous
Not applicable

Hello @Anonymous ,

 

I don't think this DAX will work as the Week_key comes from DimDate, EmpID comes from DimEmp and WorkingHours, absenceHours and FixedWorkingTime come from FactTable.

Could you help me with DAX according to the above conditions?

regards,
Mahesh

miTutorials
Super User
Super User

Have you explored the new Visual Calculations feature yet ? If not take a look at this video, this should solve your query.

 

🚀 NEW FEATURE : Magic of Visual Calculations in Power BI | MiTutorials - YouTube

 

Regards

Ismail 

Anonymous
Not applicable

Hi,
I've already tried that but it's giving me an error every time I input the values in it.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors