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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
aabati68
Frequent Visitor

Please help with CALCULATE and FILTER dax function

I know the way I am trying to solve this is not elegant at all, but I do have a simple table called "HR Data" and a measure define like this:

Headcount Employees = CALCULATE(DISTINCTCOUNT('HR Data'[Employee Id])) + 0
 
I am now trying to create another measure called "Headcount Employees one year before"  where I would like to have the number of headcounts one year before. Therefore if we are in "Quarter 1 23/24" I want the headcounts calculated for "Quarter 1 22/23".
 
Headcount Employees one year before =
SWITCH(
    SELECTEDVALUE('HR Data'[Quarter-Year]),
    "Quarter 1 23/24",CALCULATE(DISTINCTCOUNT('HR Data'[Employee Id]), FILTER('HR Data','HR Data'[Quarter-Year] = "Quarter 1 22/23")),
    "Quarter 2 23/24",CALCULATE(DISTINCTCOUNT('HR Data'[Employee Id]), FILTER('HR Data','HR Data'[Quarter-Year] = "Quarter 2 22/23")),
    "Quarter 3 23/24",CALCULATE(DISTINCTCOUNT('HR Data'[Employee Id]), FILTER('HR Data','HR Data'[Quarter-Year] = "Quarter 3 22/23")),
    "Quarter 4 23/24",CALCULATE(DISTINCTCOUNT('HR Data'[Employee Id]), FILTER('HR Data','HR Data'[Quarter-Year] = "Quarter 4 22/23")),
    "0")

 

aabati68_0-1707414685735.png

 

I don't have any date structure, and I know this is not best practice, but can you please let me know how to do it ?

Thanks

A.

1 ACCEPTED SOLUTION

lbendlin_0-1707491452870.png

Heacount Employees One Year Before = CALCULATE(sum('HR Data'[Headcount Employees]),OFFSET(-4,allselected('HR Data'),MATCHBY('HR Data'[Index])))

View solution in original post

6 REPLIES 6
lbendlin
Super User
Super User

Headcount Employees one year before =
CALCULATE(DISTINCTCOUNT('HR Data'[Employee Id]), SAMEPERIODLASTYEAR(Calendar[Date]))

 

(if you don't have a Calendar table then you should add one).

aabati68
Frequent Visitor

Thank you for the reply. I totally agree this should the right way of solving this, however I just need to build a quick proof of concept plus I am using bespoken quarters so a bit tricky to solve in that way.

I wouldn't suggest the solution I am trying to implement to anyone, but is there a simple way to fix my DAX instead ?

Thanks

A.

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Thanks, this is the expected outcome:

aabati68_0-1707483925525.png

 

lbendlin_0-1707491452870.png

Heacount Employees One Year Before = CALCULATE(sum('HR Data'[Headcount Employees]),OFFSET(-4,allselected('HR Data'),MATCHBY('HR Data'[Index])))

Wonderful, works really well, thanks a lot !

A.

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric 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.

Users online (25)