Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Power Query Subtract one column from Another

Hi Experts

 

How would you subtract one column from another in a cross tab table in Power Query - see image Below

 

Date and Region columns remain as is - i want to subtract in a new table 14/09/20 - 21/09/20, then 21/09/20 - 28/09/20 and so on until the last column in the cross tab table

Image/

 

DateRegion14/09/202021/09/202028/09/202005/10/2020
01/01/2019Scotland6613   
01/02/2019Scotland6716   
01/03/2019Scotland7171   
01/04/2019Scotland7295   
01/05/2019Scotland5719   
01/06/2019Scotland5499   
01/07/2019Scotland5064   
01/08/2019Scotland 505050726070
01/09/2019Scotland 729060956621
01/10/2019Scotland 534553006040
01/11/2019Scotland 704355805194
01/12/2019Scotland 587167417468
01/01/2020Scotland 694160046450
01/02/2020Scotland 734968405715
01/03/2020Scotland 639869915746
01/04/2020Scotland 578663077348
01/05/2020Scotland 506766755217
01/06/2020Scotland 650261105291
01/07/2020Scotland 547766726534
01/08/2020Scotland 589555505420
01/09/2020Scotland 715060965354
01/10/2020Scotland 523258816235
01/11/2020Scotland 626764495699
01/12/2020Scotland 560870057123

2 Replies

  • Anonymous , unpivot the table

    Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

     

    and then create a table with distinct dates and create a rank and then you can this period vs the last period

     

    Rank 1 = RANKX('Date','Date'[Date],,ASC,Dense)

    This period= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Rank 1]=max('Date'[Rank 1])))
    Last period= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Rank 1]=max('Date'[Rank 1])-1))

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Amit - My issue is i have multiple date for different region so i cannot have distinct dates =??? whats the work around