Forum Discussion

BenTen22's avatar
BenTen22
Regular Visitor
4 years ago
Solved

Query to return results based on highest 80% of column value

Afternoon All,

 

I'm stuck on how to tackle a problem i've been presented. My source table contains rows of hypothetical opportunties that have been asigned a Most Likely Saving (if they were to be realised). My query already filters for Opps that are still to be realised but Im looking to further reduce the number of rows by only displaying the Opps that sit within the top 80% of the total ML Value. Just starting out on the Power Query journey and may have bitten off more than I can chew on this one. 

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table_query__18"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name of efficiency / initiative", type text}, {"Detail of the idea", type text}, {"Project", type text}, {"Valid", type text}, {"Date Created", type datetime}, {"Opportunity type", type text}, {"Cost category", type text}, {"Idea Owner", type text}, {"Asset Type", type text}, {"Function", type text}, {"Discipline", type text}, {"BRAG Status", type text}, {"Fish bone category", type text}, {"McKinsey Theme", type text}, {"Speed Theme", type text}, {"Minimum saving obtainable", type number}, {"Most Likely Saving", Int64.Type}, {"Maximum saving obtainable", type number}, {"Target Implementation Date", type datetime}, {"Confidence Level", type number}, {"Saving already delivered from the efficiency", Int64.Type}, {"Target Cost to Implement", Int64.Type}, {"Actual Cost to Implement", Int64.Type}, {"Actual Implementation Date", type datetime}, {"Comments on current position providing some narrative of next steps (SharePoint to generate date of update)", type text}, {"Has a A3 / Business case been completed?", type text}, {"Link to Supporting Document (A3 / Business case etc)", type text}, {"Most likely completion date?", type any}, {"Sustainability Benefit", type text}, {"CO2 Saving", type any}, {"Delivery Unit", type text}, {"Person who generated the idea", type text}, {"Modified By", type text}, {"Modified", type datetime}, {"Created By", type text}, {"Legacy ID", type text}, {"Item Type", type text}, {"Path", type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Valid] = "Yes") and ([BRAG Status] <> "Blue") and ([Cost category] = "Cost reduction")),
    #"Sorted Rows" = Table.Sort(#"Filtered Rows",{{"Most Likely Saving", Order.Descending}})
in
    #"Sorted Rows"

 

 

  • davehus's avatar
    davehus
    4 years ago

    Hi BenTen22 ,

     

    My approach is a little different in that I've used a running total rather than top n. It gets you to 77.5% of the total for your records. See attached pbix file.

     

    Did I help you today? Please accept my solution and hit the Kudos button.

6 Replies

  • davehus's avatar
    davehus
    Icon for Memorable Member rankMemorable Member

    Hi BenTen22 ,

     

    Welcome to the world of power query. 🙂 

     

    Can you provide some dummy data and indicate on which column that you'd like to get your 80% calculated on?

     

    Thanks

     

     

    • BenTen22's avatar
      BenTen22
      Regular Visitor

      Hi davehus 

       

      Some example dummy data now included. Having scrubbed the source data i'm left with the example below. I'm then looking to return the same information but filtered/sorted to only show rows that fall in the top 80% of the total value of the Most Likely Saving Column. Doing this manually in excel I would expect the returned table to only show 1-7/8(depending on rounding). I've been playing around further and might be creating a circular reference. Also trying to make other suggestions posted here work having no luck at the minute.

       

      Cheers

       

      IDNameDetailProjectValidDate CreatedCost CategoryBRAGMinimum SavingMost Likely SavingMaximum SavingConfidence
      1Name 1Detail of Idea 11Yes01/04/2022Cost reductionAmber Â£10,000,000.00 Â£60,000,000.00 Â£ 80,000,000.0010%
      2Name 2Detail of Idea 22Yes05/05/2022Cost reductionAmber Â£30,000,000.00 Â£59,000,000.00 Â£100,000,000.0030%
      3Name 3Detail of Idea 31Yes23/05/2022Cost reductionGreen£40,000,000.00 Â£50,000,000.00 Â£60,000,000.0090%
      4Name 4Detail of Idea 43Yes01/04/2022Cost reductionAmber Â£26,997,546.00 Â£40,492,405.00 Â£53,989,873.0010%
      5Name 5Detail of Idea 51Yes11/05/2022Cost reductionAmber Â£12,000,000.00 Â£24,605,136.00 Â£35,527,078.0080%
      6Name 6Detail of Idea 64Yes24/05/2022Cost reductionRed Â£18,000,000.00 Â£20,000,000.00 Â£22,000,000.0010%
      7Name 7Detail of Idea 74Yes24/05/2022Cost reductionRed Â£15,000,000.00 Â£20,000,000.00 Â£25,000,000.0025%
      8Name 8Detail of Idea 82Yes01/04/2022Cost reductionGreen Â£5,000,000.00 Â£15,908,552.00 Â£22,970,179.0010%
      9Name 9Detail of Idea 91Yes25/04/2022Cost reductionGreen Â£2,000,000.00 Â£12,000,000.00 Â£16,000,000.0080%
      10Name 10Detail of Idea 105Yes24/02/2022Cost reductionGreen Â£10,000,000.00 Â£12,000,000.00 Â£15,000,000.0010%
      11Name 11Detail of Idea 111Yes11/06/2022Cost reductionAmber Â£2,000,000.00 Â£10,000,000.00 Â£11,000,000.0010%
      12Name 12Detail of Idea 123Yes24/02/2022Cost reductionAmber Â£10,000,000.00 Â£10,000,000.00 Â£15,000,000.0040%
      13Name 13Detail of Idea 134Yes24/02/2022Cost reductionGreen Â£10,000,000.00 Â£10,000,000.00 Â£15,000,000.0090%
      14Name 14Detail of Idea 142Yes15/11/2021Cost reductionAmber Â£8,000,000.00 Â£9,486,312.00 Â£13,697,178.0050%
      • davehus's avatar
        davehus
        Icon for Memorable Member rankMemorable Member

        Hi BenTen22 ,

         

        My approach is a little different in that I've used a running total rather than top n. It gets you to 77.5% of the total for your records. See attached pbix file.

         

        Did I help you today? Please accept my solution and hit the Kudos button.

  • KT_Bsmart2gethe's avatar
    KT_Bsmart2gethe
    Icon for Impactful Individual rankImpactful Individual

    Hi BenTen22 ,

     

    If I understand the question correctly, you can add a custom step:

    EightyPercent = Table.FirstN(
                          #"SortedRow",
                          Number.RoundUp(
                                 Table.RowCount(#"SortedRow") * 0.8
                          )
                     ),
    

     

    Regards

    KT

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, BenTen22 ;

    You could create a custom column.

    = Table.SelectRows(#"Sorted Rows", each [value] >= List.Max(#"Sorted Rows"[value])*0.2)

    Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hZjBbuMwDER/pci5QE1RsqS9tXveLyj6/7+x2STrkcmZBAhyIvw8FGck+fv7Yh/2UTYbb1Z+bdv19/b55/J+2bfr3+fl5/1fRWEVNq9/X48KZxXVrn+/bxVFUA5I4ZDSD0jhkNYOiHOIgeJCyjgoLqSMg1JfSakcsh+Myhn9QDSOqOVgNCEE7Woc4gdkF91qB2TnED8YO2cYmtU5pNkB6RxSoaQLCqZrCCmgDCEFlCEoaNjklAKnTE7BdE0OKfOA2MYpjvm6lvCWwY+b4GDETPjegRG+xxzba9+bMP4yyias75gzU96vAN05Mz4EI/CQEytaiTGWKpAwhVNutjvlWHoGulZeUlxQasyxWFFBcU5xUCqnVExA5ZQlLavQggFoYl1AaZxSMM6NU2yLWZYomLJdUCyGWeoHvNk5ZcYso+NxyjLa0lOWpReF/wen3HbsU5alZ8Qoo9NxirJUkbIsQZaM2YSWFGWpYvH+JtZlCRlh/gbDmHD/0jQT9q9omwn/o20m/L9Ms4kAWGbgrqdsOmbuclLFEgB3NakiZll+BBKzcEiJWZafAc84p3g8k2WxyGUXlJhlWSwGoAoKDrGVUwzL3wQFWhqneMyyrCWeyzIFx4xdLH7Msmcd64ICb3ZOQQB00bB4LssQhP/gkAbKEHOMmJnCLTHMUgXWfnKILxmzCS3LAWMT69JimPGOnMIsv8tifuV+dM2E/W/ePYUZXeBTmOVXWY5MIgHKIuiOsZdhlipSmMWKEi+Y+RlQUzilYQconOIpzdJ7wDUutIDinLKMQBUUHDQqpyy7WRVacGZqnOKgNE7JaZbUYl12oQXrsnNKBWUXFERAFxQkcxdaMGNdzBjuGINTKnaZIVYfhhmcghGbHNJglykgODNNDqlY/P9xljCL+zfBSffM3LN0z0wlC0fYv6aLZi5JYUZf9pxmT0bAVAJg33zIKdqbDzmxYpnnh5pY4eha4ZSa0ixWNOxphVOWu5lzypLMzimOk4ZzimGfqZzi6WyW1MYwS1JilqVVQb+aUBI/mKUKCNk5BN3aOWP5hrlzRokfzHI/4wezrAT275xSIWWIfsVL5pM1GWJN0rksVaRz2RMpU1AeSfbzFw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, value = _t, name = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}, {"value", Int64.Type}, {"name", type text}}),
        #"Sorted Rows" = Table.Sort(#"Changed Type",{{"value", Order.Descending}}),
        #"Filtered Rows" = Table.SelectRows(#"Sorted Rows", each [value] >= List.Max(#"Sorted Rows"[value])*0.2)
    in
        #"Filtered Rows"


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