cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Regular Visitor

## Snapshot inventory values and stock analysis

Hi all

I want to analyse my inventory which is like a snapshot fact table. Each line has product key, date, cost and stock.
The stock amount is logged every day for each item over several years and the cost changes on some days.

This is how my table looks. It's joined to Date and Product tables. As said earlier there is an entry for every day for years:

What I want is to be able to get my inventory value for different date points, such as year or month, etc, in a graph or table. I would like to show my stock amount over time for different products too.

I have tried with dax to do this but the resulting numbers are too big. For example, I tried = SUMX(InventoryTable, InventoryTable[Cost\$] * InventoryTable[Stock]) but this gives me huge numbers so it is obviously summing everything rather than treating each row result as it's own for each product and date.

1 ACCEPTED SOLUTION
Super User

If you know that you have an entry for every product on the last day of every month then you could create a measure like

Inventory Snapshot =
VAR ReferenceDate =
MAX ( 'Date'[Date] )
VAR Result =
CALCULATE (
SUMX ( InventoryTable, InventoryTable[Cost\$] * InventoryTable[Stock] ),
'Date'[Date] = ReferenceDate
)
RETURN
Result

If you might have some dates or products missing then it would be a bit more complicated as you would need to work out the last date within the period for which you did have data for the current product.

4 REPLIES 4
Super User

If you know that you have an entry for every product on the last day of every month then you could create a measure like

Inventory Snapshot =
VAR ReferenceDate =
MAX ( 'Date'[Date] )
VAR Result =
CALCULATE (
SUMX ( InventoryTable, InventoryTable[Cost\$] * InventoryTable[Stock] ),
'Date'[Date] = ReferenceDate
)
RETURN
Result

If you might have some dates or products missing then it would be a bit more complicated as you would need to work out the last date within the period for which you did have data for the current product.

Regular Visitor

@johnt75  I hope it's ok to ask you one further question building on this!

If I wanted to create the variable ReferenceDate for both the first and last date in a month but let's say my entire dataset started, for example 25-11-2009 and ended 10-06-2018, how would I adjust the dax to still calculate? I couldn't use MIN(DATE[DATE]) for the start because it's missing the dates prior to 25-11-2009, is that correct?

Thanks 🙂

Super User

Ideally the Date table should consist of full years, regardless of whether you have data for all the dates. It should run from Jan 1st in the first year you have data for until Dec 31st in the last year you have data for.

The idea behind using MAX('Date'[Date]) as the reference date is that you can put other columns from your date table onto the chart or table visual, e.g. Year & Month, and the MAX('Date'[Date]) will then pick up the last date in the month in the current context and use that to show the values as at the end of the month.

You could duplicate the code replacing MAX with MIN to show the values as at the start of the given month, but I'm not sure how beneficial it would be to have both. The values at the start of the month are likely to be very similar to the values at the end of the previous month so for consistency it may be better to stick to one or the other.

Regular Visitor

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors