Forum Discussion

DanieleX's avatar
DanieleX
Regular Visitor
4 years ago
Solved

Power Query VlookUp or another way?

Hello all,

I'm pretty new to PowerBi, I'm looking to manipulate the data in Power Query to have a result where the Order-ID will be my unique id to put into relation with other tables.

I have this initial data sample with the amounts for the same order split into multiple lines depending on the descriptions. 

 

order-idamount-typeamount-descriptionamount
302-8280724-3255530ItemPricePrincipal172,12
302-8280724-3255530ItemPriceTax32,7
302-8280724-3255530ItemFeesCommission-21,43
305-1931380-0225167ItemPricePrincipal106,55
305-1931380-0225167ItemPriceTax20,24
305-1931380-0225167ItemFeesCommission-14,41
305-3602247-3812336ItemPricePrincipal57,38
305-3602247-3812336ItemPriceTax12,05
305-3602247-3812336ItemFeesCommission-9,25


The result I'm looking for is something like this:

order-idamount-typePrincipal AmmountTax AmmountCommission Ammount
302-8280724-3255530ItemPrice172,1232,7-21,43
305-1931380-0225167ItemPrice106,5520,24-14,41
305-3602247-3812336ItemPrice57,3812,05-9,25


Thanks for your help

  • rsbin's avatar
    rsbin
    4 years ago

    DanieleX,

    I believe the reason "Commission" is showing up on a different line, is because the AmountType is different.

    In Power Query, use the ReplaceValues to change ItemFees to ItemPrice

    Then Pivot your AmountType

    Then Pivot AmountDescription

     

     #"Replaced Value" = Table.ReplaceValue(Source,"ItemFees","ItemPrice",Replacer.ReplaceText,{"amount-type"}),
        #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[#"amount-type"]), "amount-type", "amount"),
        #"Pivoted Column1" = Table.Pivot(#"Pivoted Column", List.Distinct(#"Pivoted Column"[#"amount-description"]), "amount-description", "ItemPrice")
    in
        #"Pivoted Column1"

    Using these steps in PQ, I get the following result.  I hope this is what you are looking for:

     

4 Replies

  • DanieleX's avatar
    DanieleX
    Regular Visitor

    Hello Amitchandak,

    Thank you for your answer.

    Unpivot on amount-description & amount column doesn't create a result that I need.

    I tried Pivot, without aggregate that it almost give me my result.
    The only problem is that Commission is on a different line

     

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

      DanieleX,

      I believe the reason "Commission" is showing up on a different line, is because the AmountType is different.

      In Power Query, use the ReplaceValues to change ItemFees to ItemPrice

      Then Pivot your AmountType

      Then Pivot AmountDescription

       

       #"Replaced Value" = Table.ReplaceValue(Source,"ItemFees","ItemPrice",Replacer.ReplaceText,{"amount-type"}),
          #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[#"amount-type"]), "amount-type", "amount"),
          #"Pivoted Column1" = Table.Pivot(#"Pivoted Column", List.Distinct(#"Pivoted Column"[#"amount-description"]), "amount-description", "ItemPrice")
      in
          #"Pivoted Column1"

      Using these steps in PQ, I get the following result.  I hope this is what you are looking for: