DAX: table variables that can be shared between measures?

colinhahn

New Member
Joined
Jan 4, 2021
Messages
11
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I am analyzing data about employee headcount and I am looking for a way to simplify my formulas.

My end goal is to be able to have measures that give me headcount on a given date, how many employees were gained between the given date and the previous month, how many were lost between the given date and the previous month, etc. If I had a table of employees on a given date, these measures become simple: I can use COUNTROWS to get the current total, EXCEPT to find the gain/loss between the date and the last month, etc.

The problem I have is that my source table is not well set up for that work. In short, we have columns for hire date, termination date, and rehire date. We have people who were terminated in the past, then rehired, and they count as active. We have people who were rehired but then reterminated, so their (new) termination date is greater than the rehire date, and we don't count them as active. Etc.

I can figure out who is active on a given date by filtering the data in a variety of ways, storing each subset of the data to a variable, and UNIONing the variable tables together.

I would like to write that code once and refer back to it in each measure, instead of copying and pasting to each measure. If that code just gave the count of who was active on a given day, I could define it as a measure and call that measure in other measures. But, I need to have the actual table so I can see, e.g., which employee IDs were active on a given day but were not active a month previously, so I get the gain and loss separately (and not just the net change).

Is there a way to do this?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,223,882
Messages
6,175,166
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top