Forum Discussion
Need DAX help with Inventory on Hand
OK cool, so it seems you just want to be able to change the date to which CreateDate is compared to. We could use parameters to create a flexible date field, that won't interact with / mess up your current data model.
Create three parameters (Modelling > New Parameter) one called day with values 1-31 with an increment of 1, one called month, values 1-12 and one called year, maybe 2000-3000.
Then create a measure that will generate your date;
Dynamic Date = Date = DATE(Parameter[Day],'Parameter 2'[Month],'Parameter 3'[Year])
Then adjust the first piece of code I gave you to use that;
Inventory on Hand = CALCULATE(COUNT('FactInventory'[EquipmentID]), [CreateDate] < [Dynamic Date], [Status] <> "Removed"))
Now you can use that measure wherever you like. If you set up three parameter controls then you can dynamically input the date you want to compare to. Hope that helps?
Thanks. I tried using something like this with a sample Date of June 1, 2019. In my real fact table there are about 10-20k equipment IDs with Create Dates before that date. Again Jun 1 is just an example - it should be similar with any date
- Anonymous6 years agoNot applicable
OK I'm less clear on what you are asking!
The last measure I gave you would calculate the inventory on hand for any given date you choose. But from your table I'm thinking what you are actually asking for is a measure that would calculate the inventory you had on hand, for every date in your data? Is that right?
- Anonymous6 years agoNot applicable
Yes that is correct. Assume a fact table with thousands of rows with an EquipmentID, a date it was created (i.e. CreateDate), a StatusDate for when the status changes, and a status description (i.e. Active, Removed). So if we pick a date of June 1, 2019 and look in the fact table we should see several rows for different Equipment IDs with a CreateDate of Jun 1, 2019 meaning they were placed into inventory on that date. But what about the thousands of Equipment IDs that were placed into Inventory on earlier days. They are still in Inventory. For example, a piece of equipment with a CreateDate of Mar 14, 2018 with no status change is still in inventory on Jun 1, 2019. I would like to count ALL of the pieces of equipment in inventory for each day. Hopefully this makes sense.
- Anonymous6 years agoNot applicable
Edit: I posted this as you posted your response - I think this should be what you need;
If that is what you are after, you could use a running total that excludes all "removed" items. Something like:
Inventory on hand by day = CALCULATE( COUNTA('FactSampleInventory'[EquipmentID]), FILTER( ALLSELECTED(FactSampleInventory[CreateDate]), ISONORAFTER(FactSampleInventory[CreateDate], MAX(FactSampleInventory[CreateDate]), DESC) ), FactSampleInventory[Status] <> "Removed" )- Anonymous6 years agoNot applicable
Still no luck with it. It appears to give similar results to the first calc