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

Get Qty SUM and Daily Opening /Closing totals from another table by date and item key

 
Hello dear friends!

I need your help! I need to get SUM of Qty from another table

 

I have 3 tables
Items, Sales and Receipts

Relationship through the ItemId field across three tables. There is also a Calendar table with a Date field linking to the Sales.Date table.

ITEMS Table
ItemidItemnameItemGroupPrice
68992ItemAA50
101187ItemBA80
105083ItemCB70
105084ITemDB40
 
RECEIPTS Table (WHInput)
DateItemidWhQtyColumn1
08.01.202268992W351301
03.01.2022101187W351341
07.01.2022105083W351261
01.01.2022105084W351441
07.01.202268992W350541
04.01.2022101187W350331
03.01.2022105083W350231
06.01.2022105084W350451
06.02.202268992W351262
02.02.2022101187W351462
05.02.2022105083W351242
02.02.2022105084W351312
08.02.202268992W350532
08.02.2022101187W350422
06.02.2022105083W350432
01.02.2022105084W350412
 
SALES Table
DateItemidCustIdQtyPriceDiscountAmountWHMonth
09.01.2022105084CUS1140040W3511
09.01.2022105084CUS12401072W3501
09.01.2022105084CUS22402064W3511
09.01.2022105084CUS61401036W3501
09.01.2022105084CUS12402064W3511
09.01.2022105083CUS11701559,5W3501
09.01.202268992CUS42501585W3511
09.01.202268992CUS11501542,5W3501
09.01.2022101187CUS2180080W350

 

Now I need to get for each day in the calendar the Opening Qty = Starting SUM(Qty) for that day, Total Input Qty = SUM(Qty) up to this day from the Receipts table, Amount of Sales on that day , Input Qty Current day = SUM(Qty) on this day from the Receipts table, and Closing Qty, taking into account the previous variables.

I tried a lot of options - unfortunately I can not get the correct result.

Total Input Qty = formula is correct if only 1 product is selected, and as soon as I select 2 or more products, it sums up everything for the selected products, but I need only for the product in the sales line.

 

Total Input Qty =
varsalesQty =CALCULATE(
 SUM( Sales[Qty] ),
 FILTER(ALL( 'Calendar' ), 'Calendar'[Date] <=MIN( 'Calendar'[Date] ) )
  )
varinputQty =CALCULATE(
 SUM( WhInput[Qty] ) ,//KEEPFILTERS(
  WhInput[Date] <=MIN( 'Calendar'[Date] )
  )
returnif(ISBLANK(salesQty), blank(), inputQty)
 


Opening QTY =
var salesQty = CALCULATE (
SUM ( Sales[Qty] ),
FILTER ( ALL ( 'Calendar' ), 'Calendar'[Date] < MIN ( 'Calendar'[Date] ) )
)
var inputQty = CALCULATE(
SUM ( WhInput[Qty] ) , //KEEPFILTERS(
//WhInput[Date] < MIN ( 'Calendar'[Date] )) //ok
FILTER ( 'WhInput', WhInput[Date] <= MIN ( 'Calendar'[Date] ))
)
var inputQtyX = IF(ISBLANK(salesQty ), BLANK(), IF(ISBLANK(inputQty), BLANK(), inputQty - salesQty))
RETURN inputQtyX

 

And I'm not really sure about the Total Input Qty MAX = formula, because for a date without a sale, the Input qty shows empty.

 

Total Input MAX =
CALCULATE(
SUM ( WhInput[Qty] ) ,
FILTER ( 'WhInput', WhInput[Date] <= MIN ( 'Calendar'[Date] )
&& WhInput[Itemid] = MIN(Sales[Itemid])
)
)

 

Screenshot 2022-09-02 at 12.18.43.png

 

Can you help - how to build functions in order to get the correct result from this data?

I really appreciate any help! Thanks in advance!

5 REPLIES 5
lbendlin
Super User
Super User

 

Now I need to get for each day in the calendar 

 

you didn't include the calendar table in your sample data.  Do you want it to be linked into the data model or do you want to keep it separate for scenarios where you have days without sales?

 

What is the significance of the "Wh" column? Is this data model appropriate for your business scenario?

 

lbendlin_0-1662335291793.png

 

Do you want it to be linked to the data model or do you want to keep it separate for scenarios where you have no sales days?
I need to be able to find the input, open and close quantity for any day in the calendar, even if there are no sales for that item on that day.

 

Thanks again!

Here would be an example of a daily breakdown by item and warehouse for sales.  Can you please indicate what the business logic for the opening and closing balance would be?  For days without sales they would stay the same?

 

lbendlin_0-1662418006663.png

 

Hi @lbendlin ! Thank you for your valuable time!

 

The business logic is such that if a product has not been sold for a certain period, for example, the first or second week of the month, or the first 10 days from the moment it first arrived at the warehouse, even if there were no sales, then it must be displayed as an opening balance and final balance. This is necessary for turnover statistics. The question will arise - why display days if there was no movement, but if you look in the context of several goods or groups of goods, then you need to take into account the start and final balance, taking into account all filtered goods - it does not matter if there was a sale or arrival of any goods or not.

Figuratively speaking, if item 68992 arrived at warehouse 651 on January 10 and the first sale is only 10 days later, then we need to display all these dates from 01 to 11 januar with the start and final balance.

 

Thank you so much!

Hi @lbendlin!

Thank you for your reply!

Here my attached PBI file.

 

 

WH = warehouse, WhInput = RECEIPTS TABLE.

PBI_Test 

I need to find a qty total for each day for each item and then for each warehouse for calendar days.

nd based on this value I need to calcualte Opening and closing qty balance .

Thanks in advance!

 

 

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.