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 🙂
I've added an update to my question. Please have a look at it. Note:
8136 has 3 reworks - all 3 need to be released for the item to be considered inactive/ released.
44862 was released the same week it was received - so it was never active
Thanks a ton in advance!
Hi Jah8900,
Thank you for sharing the details and sample data. Looks like the issue here is that the current logic is still including items in their release week. Need to exclude those and handle items that are received and released in the same week. Please try this below measure:
Active_Items_Per_Week =
VAR EndDate = MAX ( 'Calendar_active'[Date] )
RETURN
CALCULATE (DISTINCTCOUNT ( Table_query[Item_Number] ),
FILTER (
ALL ( Table_query ),
Table_query[Date_Received] <= EndDate
&& (
ISBLANK ( Table_query[Date_Released] )
|| Table_query[Date_Released] > EndDate
)
)
)
Thanks and regards,
Anjan Kumar Chippa
- v-achippa10 months agoCommunity Support
Hi Jah8900,
Thank you for sharing the updates. The logic for calculating active items per week is correct, but the difference you are seeing from week 23 onwards seems to be related to the data model and how reworks are recorded which is causing the count to differ.
I recommend raising a support ticket with Microsoft. So that the product team can directly review the data and help confirm the correct behaviour for your scenario.To raise a support ticket, kindly follow the steps outlined in the following guide:
How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn
Thanks and regards,
Anjan Kumar Chippa
- Jah890010 months agoFrequent Visitor
Thank you so much for your response (and patience :))!
The output of your measure is this:Whereas the correct output is:
The measure stops giving the right output in week 23.