Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

calculation versus previous week

Hello Community,

 

Hope you are well.

 

I would appreciate it if you could help me with the below. 

 

Table details:

The table shows the despatch schedule (in pallet quantities) of three sites. It includes dimensions such as product number, market, despatch date and transportation mode. Finally, it also includes the dates at which the extractions took place.

Outcome:

I need to calculate the differences of despatched pallets on a weekly basis , based on the two data extractions

I need to be able to filter on site (From_Location) and plant (To_Location).

 

Thank you in advance,

 

George

 

Extraction_DateProduct_NumberFrom_LocationTo_LocationOrder_NumberPallets_NumberShipment_DateTransport_Mode
01-Jan-21Prod001Site01Plant01Order00115005-Jan-21Sea
01-Jan-21Prod001Site01Plant01Order00120010-Jan-21Sea
01-Jan-21Prod002Site01Plant02Order0025005-Feb-21Truck
01-Jan-21Prod002Site01Plant02Order00210015-Feb-21Truck
01-Jan-21Prod003Site02Plant02Order0027520-Feb-21Truck
01-Jan-21Prod003Site02Plant02Order00225025-Feb-21Truck
01-Jan-21Prod004Site03Plant02Order00315005-Mar-21Truck
01-Jan-21Prod004Site03Plant02Order0035015-Mar-21Truck
01-Jan-21Prod005Site03Plant03Order0047510-Apr-21Air
01-Jan-21Prod005Site03Plant03Order0042520-Apr-21Air
01-Feb-21Prod001Site01Plant01Order00120010-Feb-21Sea
01-Feb-21Prod002Site01Plant02Order0027515-Feb-21Truck
01-Feb-21Prod003Site02Plant02Order0026020-Feb-21Truck
01-Feb-21Prod003Site02Plant02Order00225026-Feb-21Truck
01-Feb-21Prod004Site03Plant02Order00312505-Mar-21Truck
01-Feb-21Prod004Site03Plant02Order0037520-Mar-21Truck
01-Feb-21Prod005Site03Plant03Order0045015-Apr-21Air
01-Feb-21Prod005Site03Plant03Order0045010-Apr-21Air
01-Feb-21Prod006Site01Plant04Order00515025-Apr-21Truck
  • You need a Calendar table (based on Shipment Date, it should have columns for WeekNo, Year).

    Create a relationship to the main table on Shipment Date

    For the first table, you should be able to create a matrix with WeekNo, Extraction Date and a measure for SUM( Pallets Number).

    --

    The second table requires a measure using the measure already created so something like:

    MeasureX - CALCULATE(MeasureX, PREVIOUSMONTH(ExtractionDate))   

    it won't be exactly this, DAX time intelligence features work best with a calendar, so that would involve another calendar table for extraction dates.  OR you could create the previous date by calculating it manually

4 Replies

  • HotChilli's avatar
    HotChilli
    Community Champion

    "I need to calculate the differences of despatched pallets on a weekly basis , based on the two data extractions"

    What will this look like? Please show an example

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello HotChilli ,

     

    Thank you for getting back to me.

     

    I want the user to select any extraction date and to be able to see the differences of the despatched pallets, shown on a weekly basis (based on shipment date), between the selected extraction date and the previous extraction date.

     

    I assume that the first step would be to calculate the number of despatched pallets per week (based on shipment date), for each data extraction, just like the table below.

     

    The rows of the table refer to the number of pallets for each extarction date, and the columns capture the Year and Week number of the shipment date.

     

     2021           
    Extraction_Date236789101215161718
    2021.115020050 1752501505075 25 
    2021.6   200135250125755050 150

     

    The second step would be to select the latest extraction date and show the differences of the number of pallets, for each week based on shipment date.

     

     2021           
    Extraction_Date236789101215161718
    2021.6-150-200-50200-400-2525-2550-25150

     

    I would also like the user to be able to use the other dimensions (such as from location , to location , transport mode) as filters.

     

    Please let me know if this is more clear now.

     

    Kind regards,

     

    George

  • HotChilli's avatar
    HotChilli
    Community Champion

    You need a Calendar table (based on Shipment Date, it should have columns for WeekNo, Year).

    Create a relationship to the main table on Shipment Date

    For the first table, you should be able to create a matrix with WeekNo, Extraction Date and a measure for SUM( Pallets Number).

    --

    The second table requires a measure using the measure already created so something like:

    MeasureX - CALCULATE(MeasureX, PREVIOUSMONTH(ExtractionDate))   

    it won't be exactly this, DAX time intelligence features work best with a calendar, so that would involve another calendar table for extraction dates.  OR you could create the previous date by calculating it manually

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello HotChilli 

       

      I built the relationship between the Details table (fact table) and a Date table.

       

      The first table was succesfully created as suggested.

       

      PalletsQty:=sum(Details[Pallets_Number])

      Row Labels2021.12021.122021.152021.162021.172021.182021.22021.32021.62021.72021.82021.9Grand Total
      2021.11505075 25 15020050 1752501125
      2021.6125755050 150   2001352501035
      Grand Total2751251255025150150200502003105002160

       

      The second table was succesfully created only when I wrote the below measure.

       

      DeltaQty:=[PalletsQty] - CALCULATE ([PalletsQty], Details[Extraction_Year&Num] = "2021.1")

      Row Labels2021.12021.122021.152021.162021.182021.72021.82021.9Grand Total
      2021.6-2525-2550150200-400-90
      Grand Total-2525-2550150200-400-90

       

       

      Regarding the MeasureX - CALCULATE(MeasureX, PREVIOUSMONTH(ExtractionDate))  that you suggested, can you please provide more input on how it can work?

       

      For example, I can create an inactive relationship between the dates table and the details table-extraction date. But how exactly should the above measure be written? Should I use the USERELATIONSHIP function?

       

      More to that, there is always the scenario where the extracted details might happen twice during the same month. In this case, how should your recommended measure be written (PREVIOUS MONTH would not work in this case)?

       

      Thank you

       

      George