Forum Discussion

Enzilmenz's avatar
Enzilmenz
Frequent Visitor
4 years ago
Solved

Median weighted

Hi all,   i need to calculate the median price of a material taking into consideration the impact of quantity purchased for such material. So i have this table   Material Price Quantity j...
  • v-janeyg-msft's avatar
    v-janeyg-msft
    4 years ago

    Hi, Enzilmenz 

     

    I'm sorry I didn't understand your needs at first, now I do.

    You need to customize the function in power query to expand the corresponding number of rows, and then calculate the median value in desktop.

    Like this:

    let
        .......
        Custom1 = Table.TransformColumns(#"Changed Type1",{{"Quantity", each List.Transform(List.Numbers(1,_),(x)=>x/x)}}),
        #"Expanded Quantity" = Table.ExpandListColumn(Custom1, "Quantity")
    in
        #"Expanded Quantity"

    If you don't want to destroy the source table, you can duplicate a table and operate it.

    Then you can directly use this code to calculate the median value.

    Below is my sample.

    Did I answer your question? Please mark my reply as solution. Thank you very much.
    If not, please feel free to ask me.

    Best Regards,
    Community Support Team _ Janey