Forum Discussion

William_Moreno's avatar
5 years ago
Solved

Calculating between rows and columns

Hi everyone,

I need help to solver this problem:

 

Table - 1

Code01/01/202001/02/202001/03/202001/04/202001/05/202001/06/202001/07/202001/08/202001/09/2020
10050000110510201216182020

 

Table - 2

CodeQty per to
1005000010.5

 

Expected result

DateCodeT. Qty
01/01/20201005000015
01/02/20201005000012.5
01/03/20201005000015
01/04/202010050000110
01/05/20201005000016
01/06/20201005000018
01/07/20201005000019
01/08/202010050000110
01/09/202010050000110

 

Thanks in advanced

  • darentengmfs's avatar
    darentengmfs
    5 years ago

    William_Moreno 

     

    I created a dummy dataset

     

    I used the DAX formula

    It has changed the columns into rows here.

     

    It should work for your case to unpivot using DAX. Create a new table under Table Tools:

    Data_New = UNION(

    SELECTCOLUMNS('Table - 1', "Code", 'Table - 1'[Code], "Date", "01/01/2020", "Qty", 'Table - 1'[01/01/2020]),

    SELECTCOLUMNS('Table - 1', "Code", 'Table - 1'[Code], "Date", "01/02/2020", "Qty", 'Table - 1'[01/02/2020]))

     

    You might have to finish the formula until your last date, which in this case that I'm seeing, 01/09/2020.

     

    Once your new table is created, create a new column with LOOKUPVALUE:

    Qty_per_to = lookupvalue('Table - 2'[Qty per to], 'Table - 2'[Code], 'Table - 1'[Code])

     

    Then, create another column:

    T.Qty = [Qty]*[Qty_per_to]

     

5 Replies

  • Hi William_Moreno 

     

    What I would do is unpivot Table - 1.

     

    Power Query > Select your columns to unpivot > Transform tab > Unpivot Columns

     

    Then, do a merge (in Power Query) or a lookup (in DAX), Table - 1 with Table - 2 using [Code] as the key and the result is [Qty per to]. Once you've done that, you can do a multiplication column on [Qty per to] with the value that was unpivoted.