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

Calculate Remaing Value + Stock Coverage

Hi Everybody, 

 

trying to figure sth our but so far no success with all the other calculations. 

 

Following data is given: 

 

CountryProductDateInventoryDemand
Germany123401.12.20221000100
Germany123401.01.2023 200
Germany123401.02.2023 50
Germany123401.03.2023 60
Germany123401.04.2023 30
Germany123401.05.2023 40
Germany123401.06.2023 50
Germany123401.07.2023 200
Germany123401.08.2023 200
Germany123401.09.2023 80
Germany222201.12.20221000100
Germany222201.01.2023 200
Germany222201.02.2023 50
Germany222201.03.2023 60
Germany222201.04.2023 30
Germany222201.05.2023 40
Germany222201.06.2023 50
Germany222201.07.2023 0
Germany222201.08.2023 0
Germany222201.09.2023 0
Germany222201.10.2023 0
Germany222201.11.2023 0
Germany222201.12.2023 0
Poland123401.12.20221000100
Poland123401.01.2023 200
Poland123401.02.2023 50
Poland123401.03.2023 60
Poland123401.04.2023 30
Poland123401.05.2023 40
Poland123401.06.2023 50
Poland123401.07.2023 200
Poland123401.08.2023 200
Poland123401.09.2023 80
Poland222201.12.20221000100
Poland222201.01.2023 200
Poland222201.02.2023 50
Poland222201.03.2023 60
Poland222201.04.2023 30
Poland222201.05.2023 40
Poland222201.06.2023 50
Poland222201.07.2023 50
Poland222201.08.2023 100
Poland222201.09.2023 320
Poland222201.10.2023 0
Poland222201.11.2023 0
Poland222201.12.2023 0

 

And I'd like to create the Remaining stock + cover calculation to have the following result 

 

CountryProductDateInventoryDemandStart InvCoverage
Germany123401.12.20221000100

1000

1
Germany123401.01.2023 2009001
Germany123401.02.2023 507001
Germany123401.03.2023 60

650

1
Germany123401.04.2023 305901
Germany123401.05.2023 405601
Germany123401.06.2023 505201
Germany123401.07.2023 2004701
Germany123401.08.2023 2002701
Germany123401.09.2023 80700,875

 

Start Inv  = Inventory when it's the first entry. Otherwise ending inventory from prev month. 

 

Coverage will be 1 when Demand < Start Inv and when Inv < Demand then the remainer that can be covered.

 

I'd be happy to see how to create a new column in dax to have this evaluated. 

 

Thanks !

 

M

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can create a couple of calculated columns like

Start Inv = 
VAR CurrentDate = 'Table'[Date]
VAR Inventory = CALCULATE( SUM('Table'[Inventory]), ALLEXCEPT('Table', 'Table'[Country], 'Table'[Product]), 'Table'[Date] <= CurrentDate )
VAR Demand = CALCULATE( SUM('Table'[Demand]), ALLEXCEPT('Table', 'Table'[Country], 'Table'[Product]), 'Table'[Date] < CurrentDate )
RETURN Inventory - Demand

Coverage = IF( 'Table'[Demand] < 'Table'[Start Inv], 1, DIVIDE( 'Table'[Start Inv], 'Table'[Demand] ) )

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

You can create a couple of calculated columns like

Start Inv = 
VAR CurrentDate = 'Table'[Date]
VAR Inventory = CALCULATE( SUM('Table'[Inventory]), ALLEXCEPT('Table', 'Table'[Country], 'Table'[Product]), 'Table'[Date] <= CurrentDate )
VAR Demand = CALCULATE( SUM('Table'[Demand]), ALLEXCEPT('Table', 'Table'[Country], 'Table'[Product]), 'Table'[Date] < CurrentDate )
RETURN Inventory - Demand

Coverage = IF( 'Table'[Demand] < 'Table'[Start Inv], 1, DIVIDE( 'Table'[Start Inv], 'Table'[Demand] ) )

Thanks - that was the thing I was looking to do - I'll jump on the train from this one 🙂 

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.