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
willson98
Frequent Visitor

Create opening and closing stock for each month for each material

Hi everyone,

 

I am still relatively new to Power BI, and I really need help in creating a column (or measure) to define the opening stock and closing stock of each material for each month. Attached is a screenshot of part of the query table that I have developed so far. 1.PNG

Thanks!

1 ACCEPTED SOLUTION

Hi @Anonymous, thank you for the response. Now I am trying to summarize these data into a visual. These data are forecasted data, and what I am trying to achieve is to show if the closing stock each coming month exceeds the maximum capacity of the warehouse. However, when I put in the measure into the visualization, it gives me strange huge number, like total for closing stock in January is 700+, which is impossible. You can refer to the attached images below. Is there anything wrong with my method? Thanks!2.PNG3.PNG

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Whether you create a column or measure will depend how you want to use the result.  Here are some quick measures i've written:

Pallets In = SUM('YourTable'[Pallets Issued In])
Pallets Out = SUM('YourTable'[Pallets Issued Out])
openingStock = 
VAR filterEndDate = LASTDATE('YourTable'[Date])
VAR monthStart = DATE(YEAR(filterEndDate), MONTH(filterEndDate), 1)
RETURN

CALCULATE(
	[Pallets In] - [Pallets Out],
	ALLEXCEPT('YourTable', 'YourTable'[Material Code]),
	'YourTable'[Date] < monthStart
)
closingStock = 
VAR filterEndDate = LASTDATE('YourTable'[Date])
VAR monthEnd = IF(
    MONTH(filterEndDate) = 12,
    DATE(YEAR(filterEndDate) + 1, 1, 1),
    DATE(YEAR(filterEndDate), MONTH(filterEndDate) + 1, 1)
)
RETURN

CALCULATE(
	[Pallets In] - [Pallets Out],
	ALLEXCEPT('YourTable', 'YourTable'[Material Code]),
	'YourTable'[Date] < monthEnd
)


Here is a quick snap of what it looked like when i hand copied some of your data and used it with these measures:
Capture.PNG

Hi @Anonymous, thank you for the response. Now I am trying to summarize these data into a visual. These data are forecasted data, and what I am trying to achieve is to show if the closing stock each coming month exceeds the maximum capacity of the warehouse. However, when I put in the measure into the visualization, it gives me strange huge number, like total for closing stock in January is 700+, which is impossible. You can refer to the attached images below. Is there anything wrong with my method? Thanks!2.PNG3.PNG

Anonymous
Not applicable

I've done a quick test with the dummy data I had and there doesn't appear to be any issue from what I can see in the basic method.  There must be another element at play causing your strange numbers.

 

 

I'd recommend doing an export of the Visual.  You can do this by hoving over the Graph visual, finding the ... menu and selecting export.  Get that data into Excel and have a look at it.  You'll want the underlying data.

@Anonymous Thanks for the trick! I've figured out what causes the strangely huge numbers. However, now I have the actual data for the opening stock in January 2018, as shown below. How can I integrate this actual data into the measures? Apologize for not including the actual data earlier, and thanks a lot for the previous help!4.PNG

 

Anonymous
Not applicable

My Suggestion would be to convert your "Opening Stock in January 2018" into a "Pallets Issued In" value of a date before your reporting.  That way the measure simply picks it up as normal.  Because of how the measures work the date of these records could be filtered out in your reporting so they don't show in a stange manner, if thats important.

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.