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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How create a loop with dax using one month base value?

Hi Everyone,

 

I was hoping someone could help me with a part of the formula to get me to my end goal.

I want to create a matrix, which shows the "Actual Head Count", for the next two years. I have the base data for October month.

and I have joiners and leavers data. Using these data, I created one measure

*Actual HC = TOTALYTD([HC]+[Joiners]-[Leavers],DATEADD('Calendar'[Date],-1,MONTH))

 

This measure gives me accurate data up to the current year and starting from next year it shows different data. FYI, please find the bellow attachment.

yadhamurir_0-1666260164980.png

Below data that I have:-(Base data)

HCMonth-Year
598Oct-22

 

*Now, my requirement is, I want to show the Actual HC up to my calendar end date, by using the "Base Data". 

 

@amitchandak@Greg_Deckler , @PaulDBrown @Jihwan_Kim @lbendlin 

@johnt75 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Thanks for the sample data. Since I'm not sure what the data type is for your Month_year fields, I've added a new column to each table to return the end of month date to use for the relationship with the Calendar table:

new column.jpgmodel.jpg

Ok, so one way to go about this is to use the cumulative values to get the actual HC. So basically this means

Actual HC = [cumulative base head count] + [cumulative joiners] - [cumulative leavers]
I'm assuming that the Base Head Count value of 598 in October-22 is the value before the leavers/joiners of the month take place (in other words, the value at the beggining of the month)
Since the Base count is only for the starting month, the "cumulative" value is constant. So:

 

BHC = 
CALCULATE(SUM('Base Head count'[HC]), ALL(Calander))

 

For the joiners and leavers, you need measures following this pattern:

 

Joiners HC =
CALCULATE (
    SUM ( Joiners[Joiners] ),
    FILTER ( ALL ( Calander ), Calander[Date] <= MAX ( Calander[Date] ) )
)

 

Finally your Actual HC will be:

 

Actual HC = [BHC] + [Joiners HC] - [Leavers HC]

 

To get:

result.jpg

Sample PBIX attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

8 REPLIES 8
PaulDBrown
Community Champion
Community Champion

Can you please share some sample data or a link to a sample PBIX file?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thanks for the sample data. Since I'm not sure what the data type is for your Month_year fields, I've added a new column to each table to return the end of month date to use for the relationship with the Calendar table:

new column.jpgmodel.jpg

Ok, so one way to go about this is to use the cumulative values to get the actual HC. So basically this means

Actual HC = [cumulative base head count] + [cumulative joiners] - [cumulative leavers]
I'm assuming that the Base Head Count value of 598 in October-22 is the value before the leavers/joiners of the month take place (in other words, the value at the beggining of the month)
Since the Base count is only for the starting month, the "cumulative" value is constant. So:

 

BHC = 
CALCULATE(SUM('Base Head count'[HC]), ALL(Calander))

 

For the joiners and leavers, you need measures following this pattern:

 

Joiners HC =
CALCULATE (
    SUM ( Joiners[Joiners] ),
    FILTER ( ALL ( Calander ), Calander[Date] <= MAX ( Calander[Date] ) )
)

 

Finally your Actual HC will be:

 

Actual HC = [BHC] + [Joiners HC] - [Leavers HC]

 

To get:

result.jpg

Sample PBIX attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Anonymous
Not applicable

Hi @PaulDBrown 

Thanks a lot for your solution.

Anonymous
Not applicable

Hi PaulDBrown, Please find the above tables for sample data.

 

Thankyou!

 

PREVIEW
 
 
 
Anonymous
Not applicable

Hi PaulDBrown, Please find the above tables for sample data.

 

Thankyou!

 

PREVIEW
 
 
 
Anonymous
Not applicable

Base Head count Data:-

Adjusted DisciplineWeekHCMonth-Year
Base HC10/1/2022598Oct-22

 

Joiners data:-

JoinersYearMonth-Year
16202222-Oct
38202222-Nov
18202222-Dec
7202323-Jan

 

Leavers data:-

LeaversYearMonth-Year
22202222-Oct
31202222-Nov
12202222-Dec
2202323-Jan

 

 

Anonymous
Not applicable

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.