Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

LOOKUPVALUE ERROR

Hi! 

I am using powerbi and I have two different datas, a1 and a2, as in the tables below

 

 

countrydatetypevalue
peru01/01/2023old5000
peru02/01/2022old4000
peru03/01/2022old8000
peru04/01/2022old3000
peru01/01/2023new1000
peru02/01/2022new8000
peru03/01/2022new500
peru04/01/2022new9000
USA01/01/2023old4000
USA02/01/2022old6000
USA03/01/2022old7000
USA04/01/2022old2000
USA01/01/2023new5000
USA02/01/2022new8000
USA03/01/2022new9000
USA04/01/2022new4000

 

countrydatevalue A
peru01/01/20234444
peru02/01/20228000
peru03/01/20229000
peru04/01/20228000
USA01/01/20235555
USA02/01/202212000
USA03/01/20226000
USA04/01/2022889

 

 

I tried add the column New using the code below, but it does not work

 

 

 

New = LOOKUPVALUE (a1[value],a1[date],a2[date]),a1[country],a2[country],a1[type],"new")

 

 

the following error message appears: 

The name 'LOOKUPVALUE' wasn't recognized. Make sure it's spelled correctly.

How can I fix it?

 

 

the end result would be this

country     date             value A    Old      New     
peru01/01/2023444450001000
peru02/01/2022800040008000
peru03/01/202290008000500
peru04/01/2022800030009000
USA01/01/2023555540005000
USA02/01/20221200060008000
USA03/01/2022600070009000
USA04/01/202288920004000

 

3 Replies

  • Hi Anonymous ,

     

    The code you're trying is DAX, but I guess you're trying to do this in Power Query?

    If so, then you should do a merge between the two tables, multi-selecting match fields in the merge dialog window like this:

    a1[country] & a1[date] = a2[country] & a2[date]

     

    Pete

    • Anonymous's avatar
      Anonymous
      Not applicable

      I can't use merge because in the first table there are double the lines of the second table

      Are there other way?

      My dax code doesn't work in powerbi too

      • BA_Pete's avatar
        BA_Pete
        Super User

         

        Ok. Given table a1:

        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fdDLCoAgEAXQf3EdNM7Ya9k3RCtxV7uoCKLfT7AXMybIgHDQO9datY7brjIFOvcHAclflmnwswAA5bKX4EXwIYYTEqTmxAhCnHyzzOPhp05lCUR8RIIUiShBNPcjfdfGWzFMyFJKJmQnFROyEkzkeHb5zcEKieSIbyv7CNu6Ew==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [country = _t, date = _t, #"type" = _t, value = _t]),
            chgTypes = Table.TransformColumnTypes(Source,{{"date", type date}, {"value", Int64.Type}})
        in
            chgTypes

         

        And table a2:

        let
            Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkgtKlXSUTIw1AciIwMjYyDHBAiUYnUQkkZQSSMgx8LAwABF0hhJ0hJd0gSbztBgR3QrTYEAWQ7ZRkMjNI3INpqhyaFYaGGpFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [country = _t, date = _t, value = _t]),
            chgTypes = Table.TransformColumnTypes(Source,{{"date", type date}, {"value", Int64.Type}})
        in
            chgTypes

         

        Your merged table would be as follows:

        let
            Source = Table.NestedJoin(a2, {"country", "date"}, a1, {"country", "date"}, "a1", JoinKind.LeftOuter),
            expandNested = Table.ExpandTableColumn(Source, "a1", {"type", "value"}, {"type", "value.1"}),
            pivotType = Table.Pivot(expandNested, List.Distinct(expandNested[#"type"]), "type", "value.1", List.Sum)
        in
            pivotType

         

        For this output:

         

         

        Pete