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

How to store the values or While loop.

HI All...

I have Date and employee code columns. i need to store the count of the employees for last 12 months for each month. 

EX:

Last 12 monthslogicFromto 
Aug-23From Aug-23 to last 12 months counts need store under Aug-23Sep-22Aug-23
Jul-23From Jul-23 to last 12 months counts need store under jul-23Aug-22Jul-23
Jun-23From Jun-23 to last 12 months counts need store under Jun-23Jul-22Jun-23
May-23From May-23 to last 12 months counts need store under May-23Jun-22May-23
Apr-23From Apr-23 to last 12 months counts need store under Apr-23Mar-22Apr-23
Mar-23From Mar-23 to last 12 months counts need store under Mar-23Apr-22Mar-23
Feb-23From Feb-23 to last 12 months counts need store under FEB-23Mar-22Feb-23
Jan-23From Jan-23 to last 12 months counts need store under Jan-23Feb-22Jan-23
Dec-22From Dec-22 to last 12 months counts need store under Dec-22Jan-22Dec-22
Nov-22From Nov-22 to last 12 months counts need store under Nov-22Dec-21Nov-22
Oct-22From Oct-22 to last 12 months counts need store under Oct-22Nov-21Oct-22
Sep-22From Sep-22 to last 12 months counts need store under Sep-232Oct-21Sep-22



please see the below screen. i need to show three columns employees count for the last 12 month with aboce logic.

Anjaneyachari_0-1691577471800.png

 

1 REPLY 1
rubayatyasmin
Super User
Super User

Hi, @Anonymous 

 

Create a Date table first then create a relationship with the date tables date column and employee tables date column. Then use DATESINPERIOD() dax func. 

 

For instance, 

 

CALCULATE( COUNT('Employees'[employee_code]), DATESINPERIOD('DateTable'[Date], MAX('DateTable'[Date]), -12, MONTH) )

 

refer: https://learn.microsoft.com/en-us/dax/datesinperiod-function-dax

 

or you can use DATESBETWEEN(). 

 

refer: https://radacad.com/datesinperiod-vs-datesbetween-dax-time-intelligence-for-power-bi

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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