cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Petanek333
Helper III
Helper III

Calculate changes between dates for various data categories

Hi, 

I have a table like this.

Petanek333_0-1660921510201.png

and a date slicer 'Calendar'[Dates] 

Petanek333_1-1660921712115.png

 

There is data about stock movement in the table StockTable.

Column "Type" is for distinguishing between increase (1) and decrease (2) of stock.

I have several IDs and Warehouses (those are two data categories I want to analyze).

Column "Quantity" represents the amount of stock that has increased or decreased. 

Finally column "Current stock" represents the value of stock after the change.

 

I am struggling with the DAX expressions for the following views: (I suppose more than one DAX formula will be necessary)

With this slicer selection...

Petanek333_4-1660923096964.png

...I want to see this (obviously the the column names don't have to include the selected dates)

Petanek333_3-1660922810162.png

There are some key points: 

- the formula has to find the nearest earlier date in order to get a stock value for that date (for both starting and ending date)

- it has to distinguish between decrease and increase by the "Type" column as there are absolute values (or should I use the calculated column instead?)

 

...and of course the same for the Warehouse as there are several ID-Warehouse combinations.

 

Can you help me with the DAX expression please?

2 REPLIES 2
Daryl-Lynch-Bzy
Super User
Super User

Hi @Petanek333 - I would like to suggest simplifying the DAX by changing the way you import the data.  This would involve removing the "Type" (increase / decrease) and changing the Quantity to +/-.  Now the DAX would simply add the quantity movements between the required dates.

Hi @Daryl-Lynch-Bzy  and thank you for your suggestion. I will do it. Will be still struggling with the DAX though 🙂

Helpful resources

Announcements
Winner of T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Find out who won the T-Shirt Design Challenge and the top 3 finalists.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.