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
afaque03
Helper I
Helper I

Calculate On Hand quantity

Hello Freinds,

 

I have a matrix table where im showing month wise incoming and outgoing quantity and there is a filter of month. I want to calculate On-Hand quantity for the selected month. My report looks like the below image. In this report I have two columns of Incoming and outgoing quantity and now I want to calculate On hand quantity for each month product wise (the data which are blurred by blue pen is product name) and the calculation  for On hand quantity is -:

"suppose if in filter I select 3 months jan, feb and march of 2017 so On hand quantity for jan will be all the incoming quantity till dec 2016 - all outgoing quantity till dec 2016. and for feb will be will be all the incoming quantity till jan 2017 - all outgoing quantity till jan 2017

 

NOTE-: Any month can be selected from that slicer any number of month of any year so it should calculate the total quantity till the previous month, Suppose I select march, april in that slicer so for march it should calculate all the incoming quantity till feb and all outgoing quantity till feb and for april all incoming quantity till march and outgoing quantity till march and then subtract incoming and outgoing quantity.

ReportReportFilterFilter

 

 

1 ACCEPTED SOLUTION

Hi @afaque03,

 

My mistake.

 

Could you try the formula below to see if it works? Smiley Happy

On-Hand Quantity =
VAR currentYearMonth =
    MAX ( 'Table1'[YearMonth] )
VAR productName =
    FIRSTNONBLANK ( 'Table1'[Product Name], 1 )
RETURN
    CALCULATE (
        SUM ( 'Table1'[Incoming Quantity] ) - SUM ( 'Table1'[Outgoing Quantity] ),
        FILTER (
            ALL ( Table1 ),
            'Table1'[YearMonth]
                <= currentYearMonth - 1
                && 'Table1'[Product Name] = productName
        )
    )

 

Regards

View solution in original post

7 REPLIES 7
v-ljerr-msft
Employee
Employee

Hi @afaque03,

 

I assume you have a Date column called "Date" in your table.

 

First, use the formula below to add a calculate column in your table.

YearMonth = YEAR ( 'Table1'[Date] ) * 12 + MONTH ( 'Table1'[Date] )

Then you should be able to use the formula below to create a measure for On-Hand Quantity. 

On-Hand Quantity =
VAR currentYearMonth =
    MAX ( 'Table1'[YearMonth] )
RETURN
    CALCULATE (
        SUM ( 'Table1'[Incoming Quantity] ) - SUM ( 'Table1'[Outgoing Quantity] ),
        FILTER ( ALL ( Table1 ), 'Table1'[YearMonth] <= currentYearMonth - 1 )
    )

 

Regards

@v-ljerr-msftThnx for the solution. But it does not give me quantity product wise I want it to be product wise On-Hand quantity. That measure is giving me a single output for each product. for example for the month of january it is giving me 435615.86 for each product.

 

Capture3.PNG

 

 

Hi @afaque03,

 

My mistake.

 

Could you try the formula below to see if it works? Smiley Happy

On-Hand Quantity =
VAR currentYearMonth =
    MAX ( 'Table1'[YearMonth] )
VAR productName =
    FIRSTNONBLANK ( 'Table1'[Product Name], 1 )
RETURN
    CALCULATE (
        SUM ( 'Table1'[Incoming Quantity] ) - SUM ( 'Table1'[Outgoing Quantity] ),
        FILTER (
            ALL ( Table1 ),
            'Table1'[YearMonth]
                <= currentYearMonth - 1
                && 'Table1'[Product Name] = productName
        )
    )

 

Regards

@v-ljerr-msftSorry to bother you again. Can you help me to make the change in the DAX in case when there is no incoming and outgoing then On-Hand quantity of that month should get carry forwarded to onhand quantity of next month. Currently the DAX does not carry forward the On-Hand quantity. 

"On-Hand Quantity = VAR currentYearMonth = MAX (Inventory[YearMonth] ) VAR productName = FIRSTNONBLANK ( Inventory[Product Name], 1 ) RETURN CALCULATE ( SUM ( Inventory[Incoming Quantity] ) - SUM ( Inventory[Outgoing Quantity] ), FILTER ( ALL ( Inventory ), Inventory[YearMonth] <= currentYearMonth - 1 && Inventory[Product Name] = productName ) ) ". Attached is the snapshot of that report in which for the month of may the On-Hand quantity is 684 and when there is no incoming and outgoing quantity for june the On-Hand quantity also becomes blank.

 

Capture.PNG

@v-ljerr-msftThnx a lot for your solution. It worked perfectly fine. Smiley Very Happy

Hi @afaque03,

 

Great to hear the problem got resolved! Could you accept the corresponding reply as solution to close this thread? Smiley Happy

 

Regards

@v-ljerr-msftSure. Thnx again Smiley Happy

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.