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
Anonymous
Not applicable

Data Massaging help needed (pick record with max date + max sequence along with periodic sum of val)

Here is a typical requirement for Data massaging. 

Below is the structure of source data

MaterialGroupUnitWarehouseTransaction_DateSequenceR/I/AQuantityTransfer (Y/N)Qnt_post_trnRate
ItemEGroupAkgsWH109-Feb-2012 10:301Receipt20000N2000081.444
ItemDGroupBkgsWH113-Feb-2012 10:301Receipt20000N20000146.9936
ItemAGroupBkgsWH215-Feb-2012 11:161Receipt6000N6000170
ItemEGroupAkgsWH115-Mar-2012 06:241Issue7000Y1300090.7914
ItemEGroupAkgsWH215-Mar-2012 06:241Receipt7000Y700090.7914
ItemDGroupBkgsWH116-Mar-2012 06:121Issue2000Y18000156.3067
ItemDGroupBkgsWH216-Mar-2012 06:121Receipt2000Y2000156.3067
ItemEGroupAkgsWH219-Mar-2012 12:011Issue200N680090.7914
ItemAGroupBkgsWH227-Mar-2012 08:431Issue6000Y0170
ItemAGroupBkgsWH127-Mar-2012 08:431Receipt6000Y6000170
ItemDGroupBkgsWH105-Apr-2012 05:371Issue2000Y16000156.3067
ItemDGroupBkgsWH205-Apr-2012 05:371Receipt2000Y4000156.3067
ItemEGroupAkgsWH114-Apr-2012 05:111Issue201N1279990.7914
ItemEGroupAkgsWH216-Apr-2012 11:181Issue1222N557890.7914
ItemDGroupBkgsWH216-Apr-2012 11:181Issue1003N2997156.3067
ItemDGroupBkgsWH216-Apr-2012 11:182Issue300N2697156.3067

This is table for material transactions in warehouses. I need to plot Monthly chart of total receipts, total issues and closing stock with following rules.  

1) Chart for selected material Group which would contain multiple materials to show columns for Issues and receipts for the period and line for closing stock for the period i.e. Month-Year. If a specific material selected, chart to represent only for that material and not the whole group. The chart to have drilling down to the dates of months for clicked month-year. 

2) Issues and receipts shall not cover internal transfers. Rest shall be summed up for month-Year.   

3) Closing stock is sum of stocks (Qnt_post_trn) of same material in various warehouses as of latest transaction in individual warehouse.

4) Multiple transactions for same material in same warehouse at same time can happen. Latest is the one with max Sequence of latest transaction datetime. 

 

I have transformed the table at source itself like below. 

MaterialGroupUnitWarehouseTransaction_DateSequenceR/I/AQuantityTransfer (Y/N)Qnt_post_trnRateReceipt_kgReceipt_AmtIssue_kgIssue_AmtAdjustment_kgAdjustment_AmtStock_kgStock_Amt
ItemEGroupAkgsWH109-Feb-2012 10:301Receipt20000N2000081.4442000016288800000200001628880
ItemDGroupBkgsWH113-Feb-2012 10:301Receipt20000N20000146.99362000029398720000200002939872
ItemAGroupBkgsWH215-Feb-2012 11:161Receipt6000N600017060001020000000060001020000
ItemEGroupAkgsWH115-Mar-2012 06:241Issue7000Y1300090.7914000000130001180288.2
ItemEGroupAkgsWH215-Mar-2012 06:241Receipt7000Y700090.79140000007000635539.8
ItemDGroupBkgsWH116-Mar-2012 06:121Issue2000Y18000156.3067000000180002813520.6
ItemDGroupBkgsWH216-Mar-2012 06:121Receipt2000Y2000156.30670000002000312613.4
ItemEGroupAkgsWH219-Mar-2012 12:011Issue200N680090.79140020018158.28006800617381.52
ItemAGroupBkgsWH227-Mar-2012 08:431Issue6000Y017000000000
ItemAGroupBkgsWH127-Mar-2012 08:431Receipt6000Y600017000000060001020000
ItemDGroupBkgsWH105-Apr-2012 05:371Issue2000Y16000156.3067000000160002500907.2
ItemDGroupBkgsWH205-Apr-2012 05:371Receipt2000Y4000156.30670000004000625226.8
ItemEGroupAkgsWH114-Apr-2012 05:111Issue201N1279990.79140020118249.071400127991162039.129
ItemEGroupAkgsWH216-Apr-2012 11:181Issue1222N557890.7914001222110947.0908005578506434.4292
ItemDGroupBkgsWH216-Apr-2012 11:181Issue1003N2997156.3067001003156775.6201002997468451.1799
ItemDGroupBkgsWH216-Apr-2012 11:182Issue300N2697156.30670030046892.01002697421559.1699

 

Now I am able to calculate issues and receipts correctly as well as in dynamic manner. But the trouble is to pickup the closing stock dynamically for each month-year with rule 3 and 4 mentioned earlier. (That too required to be correct when drilled-down to days)

I understand that this is possible with DAX formula used to create a measure but not able to prepare the right one. 

 

Could anyone please help?

 

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

According to your requirements, you could refer to the following measure.

Measure =
VAR a =
    ALLEXCEPT ( 'Table', 'Table'[Material], 'Table'[Warehouse] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Qnt_post_trn] ),
        FILTER (
            'Table',
            'Table'[Sequence] = CALCULATE ( MAX ( 'Table'[Sequence] ), a )
                && 'Table'[Transaction_Date] = CALCULATE ( MAX ( 'Table'[Transaction_Date] ), a )
        )
    )

Here is mt test result.

1-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

This is not correct. 

Closing Stock for a period is the stock after last transaction in all warehouses put together. 

In your workout, only stock of the warehouse with latest transaction is considered. 

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.