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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Klarsen
New Member

Calculate inventory on a given date

I've got a dataset consisting of some items that are continously added to the inventory and continously removed from the inventory. In this way each item has a start date and an end date (if removed) or the end date is empty. An example is given below. I want to create a graph with drill down where you on a given date can see how many items is on the inventory and by drilling down yoy can see the items. Any suggestions about how to accomplish this?

 

Item     Start_date     End_date

Item1   1/1-2015       30/4-2016

Item2   3/2-2015       2/2-2016

Item3   4/4-2016

Item4   5/1-2015       7/6-2015

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Klarsen,

 

Here is an approach using an 'events in progress' type measure which is appropriate when your table has start and end dates.
(see this paper page 27: http://www.sqlbi.com/wp-content/uploads/DAX-Query-Plans.pdf)

 

Here is a Sample PBIX file

 

The measure looks like this.

Notes:

  • The measure will return the inventory as at the last date of the selected date range. For example, if you are browsing by month, the measure will return the inventory on the last date of the month.
  • I have included a relationship between Inventory and Date tables, but the measure doesn't need to use this, and ignores it with the ALL( 'Date' ).
Inventory Count = 
SUMX (
    GENERATE (
        CALCULATETABLE (
            SUMMARIZE (
                Inventory,
                Inventory[Start_date],
                Inventory[End_date],
                "Rows", COUNTROWS ( Inventory )
            ),
            ALL ( 'Date' )
        ),
        INTERSECT (
            DATESBETWEEN ( 'Date'[Date], Inventory[Start_date], Inventory[End_date] ),
            LASTDATE ( 'Date'[Date] )
        )
    ),
    [Rows]
)

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
BhaveshPatel
Community Champion
Community Champion

Hi There,

 

Please see this file here for the solution.

https://drive.google.com/open?id=0B5-C_3XrFPdOV19uNHlVQmNvcG8

 

 

Thanks & Regards,

Bhavesh

 

If you like my post, please hit the "Kudo" Button and mark it as solution.

 

 

Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.