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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jt1999
Frequent Visitor

Measure to Count Inventory Based On Two Distinct Dates

Hello Everyone,

 

My goal is to write a measure that will count parts based on two different dates, to ultimately get a snapshot of inventory at any set time. Here is a very basic example of what I want to accomplish:

PartIDDate_1Date_2
12341/4/20222/4/2022
56781/4/20222/4/2022
91011/4/20222/5/2022
23452/1/20222/5/2022
65432/1/20222/5/2022
43412/1/20222/6/2022
32672/1/2022 
32672/2/2022 
32672/3/2022 
32672/4/2022 

 

As you can see there are parts with distinct ID's  in the "PartID" column. Date_1, and Date_2 are when the part enters inventory, and leaves inventory, respsectfully. My goal is to be able to put in a slicer, that allows you to select a range of dates, and will tell you what the count of inventory is at any given time. 

 

For example, lets say the slicer date ranges selected are:

 

1/4/2022 to 2/3/2022 - The result should be 2

1/4/2022 to 2/4/2022 - The result should be 1

1/4/2022 to Current Day - The result should be 4, as the 4 parts without a second date are still in inventory. This would give you a live inventory calculation. 

 

Ultimately, the goal is to see goods movement in, and out at any given time period, to result in a net inventory. Maybe this would better be accomplished with 2 seperate measures, I am not sure. I hope i did a halfway decent job of what I am trying to accomplish. Any help is appreciated!

 

 

1 ACCEPTED SOLUTION
Shishir22
Solution Sage
Solution Sage

Hello @jt1999 ,

 

Create a standalone Date dimension table as DimDate not having any relationship with any other table.

Use date from DimDate in slicer.

 

Use below measure to count inventory -

 

Measure = 
Var _minDate= Min(DimDate[Date])
Var _maxDate= Max(DimDate[Date])
Return
COUNTX(FILTER(Data,Data[Date_1]<=_minDate && Data[Date_2]>=_maxDate),Data[PartID])
Cheers,
Shishir

View solution in original post

2 REPLIES 2
jt1999
Frequent Visitor

Sashir,

 

This was correct! Except for one little part. You had the >= and <= in the wrong order. I was getting a blank result, and once I switched them, it began functioning perfectly! Thank you very much, this was a HUGE help. 

Shishir22
Solution Sage
Solution Sage

Hello @jt1999 ,

 

Create a standalone Date dimension table as DimDate not having any relationship with any other table.

Use date from DimDate in slicer.

 

Use below measure to count inventory -

 

Measure = 
Var _minDate= Min(DimDate[Date])
Var _maxDate= Max(DimDate[Date])
Return
COUNTX(FILTER(Data,Data[Date_1]<=_minDate && Data[Date_2]>=_maxDate),Data[PartID])
Cheers,
Shishir

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.