Forum Discussion

gaikwadaa123's avatar
gaikwadaa123
Helper II
5 years ago
Solved

Percentage between two columns

Hello,    I have two tables as below  Table 1: Actual Data  Table 2 :  History Data.      I would like to caluculate the percentage error  between the two columns DBDryBulb-A and D...
  • Jimmy801's avatar
    5 years ago

    Hello gaikwadaa123 

     

    you can join both tables by the datetime column and then expand your F-Column and then the needed calculation

    Here an example

    let
        A = 
        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUAyIjAyNDBQNDKwMDJR0lQ6VYHVQJI4iEkVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t, #"DBDryBulb-A" = _t]),
            #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"DBDryBulb-A", Int64.Type}}, "de-DE")
        in
            #"Changed Type",
        B= 
        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDUAyIjAyNDBQNDKwMDJR0lY6VYHVQJI4iEiVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [DateTime = _t, #"DBDryBulb-F" = _t]),
            #"Changed Type" = Table.TransformColumnTypes(Source,{{"DateTime", type datetime}, {"DBDryBulb-F", Int64.Type}}, "de-DE")
        in
            #"Changed Type",
        JoinTables= Table.NestedJoin
        (
            A,
            "DateTime",
            B, 
            "DateTime",
            "B",
            JoinKind.LeftOuter
        ),
        #"Expanded B" = Table.ExpandTableColumn(JoinTables, "B", {"DBDryBulb-F"}, {"DBDryBulb-F"}),
        #"Added Custom" = Table.AddColumn(#"Expanded B", "Custom", each ([#"DBDryBulb-A"]-[#"DBDryBulb-F"])/[#"DBDryBulb-A"])
    in
        #"Added Custom"

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.


    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

  • v-yingjl's avatar
    v-yingjl
    5 years ago

    Hi gaikwadaa123 ,

    After merging two tables, please detect the data type for each column, if the data type is wrong, it could cause the wrong calculation result.

     

    Best Regards,
    Community Support Team _ Yingjie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.