Forum Discussion

alex779's avatar
alex779
Frequent Visitor
2 years ago

adding columns whose values are also based on scaling values in different table

Hello there!

 

Have 2 tables (PVprod and StrutturaCER). I need to add new columns named "Pn" (n=1,2,...) to first table PVprod.
Pn = reference column IRR * a scaling coefficient PVnew[n] taken from column PVnew of the second table "StrutturaCER", where n is the row index of PVnew (see pics below)


Is this at all possible in P.Bi ?

I'd like to get as many new colums added to table PVprod for all values of PVnew (including zero values).

Any idea / suggestion  in DAX?

Thanks a lot, Alex

 

 

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, alex779 

    Based on the information you have provided, I created two tables, Table1 and Table2.


    Then New Column, multiply ScalingFactor of Table2 and Value1 of Table1 to get a new column.

     

    Column = 
         Table1[Value1] * RELATED(Table2[ScalingFactor])

     

     

    This enables calculations across tables, so if you want to do more with your table, provide me with more data.

     

    How to Get Your Question Answered Quickly 

    Best Regards

    Yilong Zhou

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • alex779's avatar
      alex779
      Frequent Visitor

      thank you but my tables are NOT of the same size.. So it does not work for me.
      My Table1 is like 9000 rows and Table2 (scalingfactors) only 10 rows. I had to rescale each of the 9000 cells IRR in a new column with scaling factors taken from Table2, and add as many columns as the 10 scaling factors.. 

  • wdx223_Daniel's avatar
    wdx223_Daniel
    Icon for Community Champion rankCommunity Champion

    M Code

    =Table.FromRecords(Table.TransformRows(PVprod,each Record.TransformFields(_,List.Transform(List.Position(StrutturaCER[PVnew]),(r)=>{"P"&Text.From(r),(x)=>[IRR]*StrutturaCER[PVnew]{r}}),2)))

    • alex779's avatar
      alex779
      Frequent Visitor

      Hi, thanks but getting this error. Seems a "ciclic error during evaluation"



       

       

      • wdx223_Daniel's avatar
        wdx223_Daniel
        Icon for Community Champion rankCommunity Champion

        it's not a formula in Custom Column

        it's a whole step code, try to delete Table.AddColumn outside

  • alex779's avatar
    alex779
    Frequent Visitor

    THanks a lot both guys. Would like to attach my pbix example file but HOW???? 
    I drag the pbix here but got "file type (.pbix) is not supported." Cannot find the icon to attach file anywhere.