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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Chuck1892
Frequent Visitor

Return last Value by Date and grouped by ID

Hello folks,


I have a problem that has been bothering me for a few days now. I have a log table that shows the state change of a position (ID).
I would now like to use the log to determine which positions were set to "Active" in each fiscal week.
The "result" tables needs the explicit IDs for further calculations, but for now I want to calculate the number of positions per fiscal week.


Example Log:

Chuck1892_0-1716378602520.png

 


My first theory thought was to filter the log by fiscal week and then summarize it by position_id and get the Latest "changedTo" for each position_id. Then i would filter the summarized table and volià ... All active positions.

But annoyingly, the technical DAX implementation is lacking on my part.


As far as i understand, it is not possible to reference a column of a "variable table". So something like this would not work .. (hardcored _curKW for testing)

 

 

VAR _curKW = 202421
VAR _filteredStateChange =
CALCULATETABLE(
'EmploymentPosition StateChange',
'EmploymentPosition StateChange'[ISO YearFW] < _curKW
)
VAR _lastPosState_inKW =
SUMMARIZE(
_filteredStateChange,
'EmploymentPosition StateChange'[employmentPosition_id],
"LastChange",
MAX(_filteredStateChange[changedTo])
)

 


Unfortunately, I can't think of any other way - would anyone here have any ideas to steer me in the right direction?

I would be grateful for any help!


Regards!

3 REPLIES 3
some_bih
Super User
Super User

Hi @Chuck1892 so basically, your expected results should be which employee was active during each fiscal weeks?

If yes, one approach is to 

 

ADDCOLUMNS (
SUMMARIZE (YourCentralTableName, FiscalweekID, EmployeeID), "Number of distinct stautus", CALCULATE (DISTINCTCOUNT(YourTableName), column changed to="Active"))

 

After that filter this table using variable to status Active or what is your definition for Active, as you have blank in column changed to.

The best would be to share file and provide expected examples.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






some_bih
Super User
Super User

Hi @Chuck1892 

It could be that your analysis need only one set of data: <YourTableName>[changedTo] column value is "Active"?

If yes then one of possible option is to use Power Query step to filter only that column and this status.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






Hey! Thanks for your reply.
Unfortunately, that wouldn't work. For the final visualisation, the values should be displayed depending on the calendar week.
For example, if position 1234 is set to active in calendar week 1, inactive in calendar week 3 and active again in calendar week 4 and position 9876 is set so active in week 2 and inactive in week 4 then the calculated table (simplified) should look like this (The variable _curKW would normally be SELECTEDVALUE(Calendar[YearFiscalWeek] )


For YearFiscalWeek = 202402

employmentPosition_idLastChange
1234Active

9876

Active

So there are two active positions in Week 02

 

For YearFiscalWeek = 202403

employmentPosition_idLastChange
1234Inactive

9876

Active

Active Positions in Week 03 = 1

I hope my explanations are reasonably understandable. 😅


//Edit: Found an example in the logfile!

Chuck1892_1-1716391742270.png

 

If I filter the log to active only, both employmentPositions would be counted both in FiscalWeek 19 (Pink - which would be correct) and in FiscalWeek 20 (yellow), which would be wrong, as they have been set to inactive.

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.