Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
gadao
Frequent Visitor

How to Divide multiple columns at once by another column

I'm creating a fact table based on another fact table and i need to do a simple thing but i'm not getting it.

 

I have something like 5 values columns, each columns bring up aspects of the value. But something is related to all these columns, they all show values related to the total value of the installment program. I have another column that shows that number of installments, all i need to do is divide each of these 5 columns by the column that contains the number of installments.

 

I tried to use this: 

= Table.TransformColumns(NameOfPreviousStep, List.Transform({"Column1", "Column2"}, each {_, (inner) => inner / 45, type number}))

 

I changed this {"Column1", "Column2"to the 5 columns that i need to divide

The problem occurs when a change the 45 to the column which contais the number of installment.

 

I think i have to do something like the "_" to represents each row for the Númber of Installment.

 

I can definily workaround this, but it seems so simple and usual that I would like to learn what i'm missing here.

 

I appreciate any help if possible.

1 ACCEPTED SOLUTION
jennratten
Super User
Super User

Hi - this is how it can be done...

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmMgNjFVitWholAsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Installments = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Installments", Int64.Type}}),
    ColumnsToDivide = {"Column1", "Column2", "Column3"},
    Test = Table.FromRecords(
        Table.TransformRows(
        #"Changed Type",
        (r) => 
        Record.TransformFields(
            r,
            List.Transform(
                ColumnsToDivide,
                each {_, each _ / r[Installments]}
            )
        )
    ),
    Value.Type(#"Changed Type")
)

in
    Test

 

jennratten_0-1633704598237.png

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

View solution in original post

4 REPLIES 4
JimDavis
New Member

Even simpler: unpivot the columns so the values you want to divide are all in the same column, then divide this column and re-pivot them.

 

wdx223_Daniel
Super User
Super User

=Table.ReplaceValue(NameOfPreviousStep,each [NoOfInstallment],"",(x,y,z)=>x/y,{"Column1","Column2","Column3"})

I was looking for something similar and it works for me. But I don't know how it works. Could you explain this part: each [NoOfInstallment],"",(x,y,z)=>x/y?

 

Also I would like to modify this that it only works when NoOfInstallment > 0, but when I modify to each [NoOfInstallment] > 0, the result is no division on any of the values.

jennratten
Super User
Super User

Hi - this is how it can be done...

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmMgNjFVitWholAsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Installments = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Installments", Int64.Type}}),
    ColumnsToDivide = {"Column1", "Column2", "Column3"},
    Test = Table.FromRecords(
        Table.TransformRows(
        #"Changed Type",
        (r) => 
        Record.TransformFields(
            r,
            List.Transform(
                ColumnsToDivide,
                each {_, each _ / r[Installments]}
            )
        )
    ),
    Value.Type(#"Changed Type")
)

in
    Test

 

jennratten_0-1633704598237.png

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.