Forum Discussion
Events in Progress Problem
- 10 months ago
Thank you all for the responses. Appreciate all the help 🙂
I've figured out the logic. So, the right way to calculate events in progress is to set min and max dates (to count the number of days an item is open between its arrival and departure). In my case, I didn't care for the arrival date, but only the max date. I created a calculated column in my calendar table "Week End Date". For an item to be active/ open, it had to:
- have arrived on or before the max date (i.e. Week End Date)
AND
- have been released after the max date OR have a blank release date.
So, this is the DAX:ActiveItems =
VAR _maxDate = MAX( 'Calendar_active'[Week End Date] )-- get all ItemKeys but remove only the Calendar filter so we still respect other slicers/filters (ItemKey is a combination of Item_Number and Date_Received)
VAR _Items =
CALCULATETABLE(
VALUES( 'Table_query'[ItemKey] ),
REMOVEFILTERS( 'Calendar_active' )
)RETURN
SUMX(
_Items,
VAR _minEff =
CALCULATE(
MIN( 'Table_query'[Date_Received] ),
REMOVEFILTERS( 'Calendar_active' )
)
VAR _maxRel =
CALCULATE(
MAX( 'Table_query'[Date_Released] ),
REMOVEFILTERS( 'Calendar_active' )
)
RETURN
IF(
_minEff <= _maxDate
&& ( ISBLANK( _maxRel ) || _maxRel > _maxDate ),
1,
0
)
)
//
The reason I'm using ItemKey is:
- An item can come into stock for more than one rework. Each rework is entered as a separate row. But an item is not considered fully released until ALL its reworks are released.
And
- An item can come into stock, have reworks done on it, and be released.
- The same item can enter stock again a week or so later.
By using a combination of Item_Number and Date_Received, I group all the reworks together so they are considered one item, and if the item enters stock again after being released, then it is counted again (since it will have a different Date_Received).
Hope that makes it clear 🙂
Thank you all for the responses. Appreciate all the help 🙂
I've figured out the logic. So, the right way to calculate events in progress is to set min and max dates (to count the number of days an item is open between its arrival and departure). In my case, I didn't care for the arrival date, but only the max date. I created a calculated column in my calendar table "Week End Date". For an item to be active/ open, it had to:
- have arrived on or before the max date (i.e. Week End Date)
AND
- have been released after the max date OR have a blank release date.
So, this is the DAX:
ActiveItems =
VAR _maxDate = MAX( 'Calendar_active'[Week End Date] )
-- get all ItemKeys but remove only the Calendar filter so we still respect other slicers/filters (ItemKey is a combination of Item_Number and Date_Received)
VAR _Items =
CALCULATETABLE(
VALUES( 'Table_query'[ItemKey] ),
REMOVEFILTERS( 'Calendar_active' )
)
RETURN
SUMX(
_Items,
VAR _minEff =
CALCULATE(
MIN( 'Table_query'[Date_Received] ),
REMOVEFILTERS( 'Calendar_active' )
)
VAR _maxRel =
CALCULATE(
MAX( 'Table_query'[Date_Released] ),
REMOVEFILTERS( 'Calendar_active' )
)
RETURN
IF(
_minEff <= _maxDate
&& ( ISBLANK( _maxRel ) || _maxRel > _maxDate ),
1,
0
)
)
//
The reason I'm using ItemKey is:
- An item can come into stock for more than one rework. Each rework is entered as a separate row. But an item is not considered fully released until ALL its reworks are released.
And
- An item can come into stock, have reworks done on it, and be released.
- The same item can enter stock again a week or so later.
By using a combination of Item_Number and Date_Received, I group all the reworks together so they are considered one item, and if the item enters stock again after being released, then it is counted again (since it will have a different Date_Received).
Hope that makes it clear 🙂
- v-achippa10 months agoCommunity Support
Hi Jah8900,
Thank you for the response and confirming that this DAX is working for you. I request you to please mark this post as Accept as Solution so that other community members who has similar issue will find it more easily.
Thanks and regards,
Anjan Kumar Chippa