Forum Discussion

Matt_JEM's avatar
Matt_JEM
Icon for Helper I rankHelper I
1 year ago
Solved

Tracking stock in different warehouses

Good day Everybody.   I am new to Power Bi and would appreciate your help.   We have stockcodes for each project that move to different locations (Warehouse) in the factory. Each time a stockcode...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi all,thanks for the quick reply, I'll add more.

    Hi Matt_JEM ,

    Regarding your question, your raw data appears to be sorted in chronological order. My idea would be to group based on the column 'Stock code' column and then create index columns. The largest row of the index column is the final Warehouse.

    Please follow these steps:

    1.

    2.

    Table.AddIndexColumn([Summarize],"Index",1)

    3.

    Complete m code

    let
        Source = yourfilepath,
        Table_Sheet = Source{[Item="Table",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Table_Sheet, [PromoteAllScalars=true]),
        #"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"Trn Qty"}),
        #"Grouped Rows" = Table.Group(#"Removed Columns", {"StockCode"}, {{"Summarize", each _, type table [StockCode=text, Warehouse=text, NewWarehouse=nullable text, EntryDate=text, TrnTime=text]}}),
        #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Index", each Table.AddIndexColumn([Summarize],"Index",1)),
        #"Removed Columns1" = Table.RemoveColumns(#"Added Custom",{"StockCode", "Summarize"}),
        #"Expanded Index" = Table.ExpandTableColumn(#"Removed Columns1", "Index", {"StockCode", "Warehouse", "NewWarehouse", "EntryDate", "TrnTime", "Index"}, {"StockCode", "Warehouse", "NewWarehouse", "EntryDate", "TrnTime", "Index.1"})
    in
        #"Expanded Index"

    4.Use the following DAX expression to create a measure

    Measure = 
    VAR _endWarehouse = CALCULATE(MAX('Table'[Index.1]),ALL('Table'[Warehouse]))
    VAR _currentWarehouse = MAX('Table'[Index.1])
    VAR _result = IF(_currentWarehouse = _endWarehouse," ")
    RETURN _result

    5.Final output

     

    Best Regards,
    Wenbin Zhou