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
Hamdan1234
Helper III
Helper III

Increase and decrease based on values of other column

I have two tables. I want a column or measure based on, if there are sales in INV_Type column then value of beginning inventory should be decreased based on Qty column. So if QTY column has 3 and INV_Type is sales then the beginning inventory should be reduced by 3. If INV_Type is  out it should also decrease from beginning inventory ,if purchase or INN is there in INV_Type then it should add based on quantity column for each Item ID Type. It should be taking beginning inventory from second table. The CO_ID represents years. We can also fixed the beginning inventory for each item type like if we fix it to 100 for 2019 based on INV_Type it should keep on adding or subtracting. Please let me know if possible. 
Thanks

Year               ITEM_ID  INV_ID QTY   INV_TYPE  CO_ID
17/01/2019800012Sales2019
18/02/2019990023Sales2019
20/10/2019990031INN2019
21/11/2019800044Purchase2019
25/02/2020990055Sales2020
11/05/2020800063Sales2020
10/10/2020990077Purchase2020
19/11/2020990085out2020
17/01/2019800091Sales2019
19/02/20198000102Sales2019
22/10/20198000112INN2019
21/11/20198000125Purchase2019
ITEM_IDBEG_QTYCO_ID
99001002019
8000502019
9900102020
800052020

 

 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @Hamdan1234 

 

You can try the following methods.

change =
IF (
    [INV_TYPE] = "Sales",
    - [QTY],
    IF (
        [INV_TYPE] = "out",
        - [QTY],
        IF (
            [INV_TYPE] = "Purchase",
            + [QTY],
            IF ( [INV_TYPE] = "INN", + [QTY], BLANK () )
        )
    )
)

vzhangti_0-1639449017090.png

Sum change =
CALCULATE (
    SUM ( 'Table 1'[change] ),
    FILTER (
        'Table 1',
        [ITEM_ID] = EARLIER ( 'Table 2'[ITEM_ID] )
            && [CO_ID] = EARLIER ( 'Table 2'[CO_ID] )
    )
)
Final Oty = [BEG_QTY]+[Sum change]

vzhangti_1-1639449116536.png

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @Hamdan1234 

 

You can try the following methods.

change =
IF (
    [INV_TYPE] = "Sales",
    - [QTY],
    IF (
        [INV_TYPE] = "out",
        - [QTY],
        IF (
            [INV_TYPE] = "Purchase",
            + [QTY],
            IF ( [INV_TYPE] = "INN", + [QTY], BLANK () )
        )
    )
)

vzhangti_0-1639449017090.png

Sum change =
CALCULATE (
    SUM ( 'Table 1'[change] ),
    FILTER (
        'Table 1',
        [ITEM_ID] = EARLIER ( 'Table 2'[ITEM_ID] )
            && [CO_ID] = EARLIER ( 'Table 2'[CO_ID] )
    )
)
Final Oty = [BEG_QTY]+[Sum change]

vzhangti_1-1639449116536.png

 

Best Regards,

Community Support Team _Charlotte

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

lbendlin
Super User
Super User

Quick reminder that Power BI is a reporting tool, not a stock/inventory management tool.

 

What's the start date for your years? Jan 1st?

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.