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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
carted01
Frequent Visitor

Cummulative Total by Date that doesn't go negative

Hi,

I have a report that takes a daily forecast of sales by product, and combines it with incoming stock, in order to produce a forecast Stock on Hand for any given date in the future.

 

I have managed to create a "Forecast SOH" in the below table using the below formula. The problem however is when stock is depleted to zero, the forecast sales keep depleting the Forecast SOH more and more into the negative. In the real world, however, in spite of the forecast sales, zero sales are occuring because there is zero stock on hand to sell. The result I am chasing is the "Desired Forecast SOH" column, whereby once stock hits zero, it stays on zero until a postive "Net Stock Movement" occurs.

 

Any advice on how to acheive this would be greatly appreciated.

 

Forecast SOH =
CALCULATE(
    SUM('Incoming Stock'[Net Stock Movement]),
    FILTER(
        ALLSELECTED('Incoming Stock'[Date]),
        ISONORAFTER('Incoming Stock'[Date], MAX('Incoming Stock'[Date]), DESC)
    )
)
 
DateNet Stock MovementForecast SOHDesired Forecast SOH
22/04/2022000
23/04/2022000
24/04/2022000
25/04/2022000
26/04/2022-324-3240
27/04/2022-101-4250
28/04/2022-17-4420
29/04/20220-4420
30/04/20220-4420
1/05/20220-4420
2/05/2022-119-5610
3/05/2022-32-5930
4/05/202267885678
5/05/20227398241417
6/05/202208241417
7/05/202208241417
8/05/202208241417
9/05/2022-1996251218
10/05/2022-325921186
11/05/2022-785151108
12/05/2022-135021095
13/05/202205021095
14/05/202205021095
15/05/202205021095
16/05/2022-279223816
17/05/2022-32190784
18/05/2022-78112706
19/05/2022-1399693
20/05/2022100811071701
21/05/2022011071701
22/05/2022011071701
23/05/2022-1199881582
24/05/2022-659241517
25/05/2022-1567681361
26/05/2022-267421335
27/05/202207421335
28/05/202207421335
29/05/202207421335
30/05/2022-786641258
31/05/202243711011695
1/06/2022-1529491542
2/06/2022-259231517
3/06/202209231517
6 REPLIES 6
v-xiaotang
Community Support
Community Support

Hi @carted01 

I just want to confirm if you resolved this issue? If yes, you can accept the answer helpful as the solution or share you method and accept it as solution, thanks for your contribution to improve Power BI.

If you need more help, please let me know.

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Whitewater100
Solution Sage
Solution Sage

Hi:

Does something like this make sense?

 

Stock Calc = 

VAR SOHcheck = CALCULATE(Forecast SOH, DATEADD(Dates,Date, -1, DAY)
return
IF(AND( SOHcheck <0, Incoming stock +[Forecast SOH] < 0), BLANK, [Forecast SOH])
))

* I don't know your incoming stock measure.

Basically seeing if your Forecast SOH was negative yesterday and despite any new stock coming in to cover forecasted sales, it is still negative, then BLANK, otherwise use your Forecast SOH measure. Something like this.

I hope this helps directionally..

tamerj1
Super User
Super User

Hi @carted01 

you may tey this measure

Forecast SOH =
VAR IerationTable =
    FILTER (
        ALLSELECTED ( 'Incoming Stock' ),
        'Incoming Stock'[Date] <= MAX ( 'Incoming Stock'[Date] )
            && 'Incoming Stock'[Net Stock Movement] > 0
    )
RETURN
    SUMX ( IerationTable, 'Incoming Stock'[Net Stock Movement] )

Thank you for the suggestion. Isn't quite getting the result however. It seems to use the positive figures only in all circumstances, however it does need to deplete with the negatives where the end result is greater than zero:

 

DateNet Stock MovementForecast SOH (Tamerj1)Desired SOH
22/04/20220 0
23/04/20220 0
24/04/20220 0
25/04/20220 0
26/04/2022-324 0
27/04/2022-101 0
28/04/2022-17 0
29/04/20220 0
30/04/20220 0
1/05/20220 0
2/05/2022-119 0
3/05/2022-32 0
4/05/2022678678678
5/05/202273914171417
6/05/2022014171417
7/05/2022014171417
8/05/2022014171417
9/05/2022-19914171218
10/05/2022-3214171186
11/05/2022-7814171108
12/05/2022-1314171095
13/05/2022014171095
14/05/2022014171095
15/05/2022014171095
16/05/2022-2791417816
17/05/2022-321417784
18/05/2022-781417706
19/05/2022-131417693
20/05/2022100824251701
21/05/2022024251701
22/05/2022024251701
23/05/2022-11924251582
24/05/2022-6524251517
25/05/2022-15624251361
carted01
Frequent Visitor

Thank you for the suggestion, unfortunately it does not acheive the desired forecast. See table below.

 

As an FYI if it helps provide some clarity, the excel formula used in the below table (in E3 and filling down) is =IF(E2+B3<0,0,E2+B3)

 

DateNet Stock MovementForecast SOHForecast SOH (Amit)Desired SOH
22/04/20220000
23/04/20220000
24/04/20220000
25/04/20220000
26/04/2022-324-324-3240
27/04/2022-101-425-4250
28/04/2022-17-442-4420
29/04/20220-442-4420
30/04/20220-442-4420
1/05/20220-442-4420
2/05/2022-119-561-5610
3/05/2022-32-593-5930
4/05/202267885678678
5/05/20227398247391417
6/05/2022082401417
7/05/2022082401417
8/05/2022082401417
9/05/2022-199625-1991218
10/05/2022-32592-321186
11/05/2022-78515-781108
12/05/2022-13502-131095
13/05/2022050201095
14/05/2022050201095
15/05/2022050201095
16/05/2022-279223-279816
17/05/2022-32190-32784
18/05/2022-78112-78706
19/05/2022-1399-13693
20/05/20221008110710081701
21/05/20220110701701
22/05/20220110701701
23/05/2022-119988-1191582
24/05/2022-65924-651517
25/05/2022-156768-1561361
26/05/2022-26742-261335
27/05/2022074201335
28/05/2022074201335
29/05/2022074201335
30/05/2022-78664-781257
31/05/202243711014371694
1/06/2022-152949-1521542
2/06/2022-25923-251517
3/06/2022092301517
4/06/2022092301517
5/06/2022092301517
6/06/2022092301517
7/06/2022-102822-1021415
8/06/202247812994781893
9/06/2022-251274-251868
10/06/20220127401868
11/06/20220127401868
12/06/20220127401868
13/06/2022-761198-761792
14/06/2022-641134-641728
15/06/2022-152982-1521576
16/06/2022-25956-251551
17/06/2022095601551
18/06/2022095601551
19/06/2022095601551
20/06/202280617628062357
21/06/2022-641699-642293
22/06/2022-1521546-1522141
23/06/2022-251521-252116
24/06/20220152102116
25/06/20220152102116
26/06/20220152102116
27/06/2022-761445-762040
28/06/2022-641381-641976
29/06/2022-1521229-1521824
30/06/2022-251203-251799
1/07/20220120301799
2/07/20220120301799
3/07/20220120301799
4/07/2022-771127-771722
5/07/2022-641063-641658
6/07/2022-154909-1541504
7/07/2022-26883-261478
8/07/202275616397562234
9/07/20220163902234
10/07/20220163902234
11/07/2022-771563-772157
12/07/2022-641499-642093
13/07/2022-1541345-1541939
14/07/2022-261319-261913
15/07/202275620757562669
16/07/20220207502669
17/07/20220207502669
18/07/2022-771999-772592
19/07/2022-641935-642528
20/07/2022-1541781-1542374
21/07/2022-261755-262348
22/07/20221260301512603608
23/07/20220301503608
24/07/20220301503608
25/07/2022-772939-773531
26/07/2022-642875-643467
27/07/2022-1542721-1543313
28/07/2022-262695-263287
29/07/20220269503287
30/07/20220269503287
31/07/20220269503287
1/08/2022-902606-903197
2/08/2022-752531-753122
3/08/2022-1802351-1802942
4/08/2022-302321-302912
5/08/20220232102912
6/08/20220232102912
7/08/20220232102912
8/08/2022-902232-902822
9/08/2022-752157-752747
10/08/2022-1801977-1802567
11/08/2022-301947-302537
12/08/20220194702537
13/08/20220194702537
14/08/20220194702537
15/08/2022-901858-902447
16/08/2022-751783-752372
17/08/2022-1801603-1802192
18/08/2022-301573-302162
19/08/20220157302162
20/08/20220157302162
21/08/20220157302162
22/08/2022-901484-902072
23/08/2022-751409-751997
24/08/2022-1801229-1801817
25/08/2022-301199-301787
26/08/20220119901787
27/08/20220119901787
28/08/20220119901787
29/08/202279219927922579
30/08/2022-751917-752504
31/08/2022-1801737-1802324
1/09/2022-341703-342290
2/09/20220170302290
3/09/20220170302290
4/09/20220170302290
5/09/2022-1031600-1032187
6/09/2022-861514-862101
7/09/2022-2061308-2061895
8/09/2022-341274-341861
9/09/20220127401861
10/09/20220127401861
11/09/20220127401861
12/09/2022-1031171-1031758
13/09/2022-861085-861672
14/09/2022-206879-2061466
15/09/2022-34844-341432
16/09/2022084401432
17/09/2022084401432
18/09/2022084401432
19/09/2022-103741-1031329
20/09/2022-86655-861243
21/09/2022-206449-2061037
22/09/2022-34415-341003
23/09/2022041501003
24/09/2022041501003
25/09/2022041501003
26/09/2022041501003
27/09/2022-137278-137866
28/09/2022-20672-206660
29/09/2022-3437-34626
30/09/20220370626
1/10/20220370626
2/10/20220370626
3/10/2022-87-50-50539
4/10/2022-73-123-123466
amitchandak
Super User
Super User

@carted01 , Try like

 

Forecast SOH =

var _1 = CALCULATE(
SUM('Incoming Stock'[Net Stock Movement]),
FILTER(
ALLSELECTED('Incoming Stock'[Date]),
ISONORAFTER('Incoming Stock'[Date], MAX('Incoming Stock'[Date]), DESC)
)
)
var _max = minx(filter(values('Incoming Stock'[Date]) , _1 >0), 'Incoming Stock'[Date])
return CALCULATE(
SUM('Incoming Stock'[Net Stock Movement]),
FILTER(
ALLSELECTED('Incoming Stock'[Date]),
ISONORAFTER('Incoming Stock'[Date], MAX('Incoming Stock'[Date]), DESC) && 'Incoming Stock'[Date] >= _max
)

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors