簡體   English   中英

佣金拆分計算 PowerBI/ Excel/Python/Tableau

[英]Commission Split Calculation PowerBI/ Excel/Python/Tableau

我需要從圖中導出的數據中創建一個衡量標准,有時總金額將是來自一位代表(即 Kate Pearson)的 1000 美元,而在其他時候它將由兩個人(Kate 和 Randal,每個人有 500 美元)甚至三。

它有點類似於 Python 中的 argmax,但我無法弄清楚以這種方式提取數據要使用什么計算。

我想要的是每個機會,一個或多個人的總數列表,如果超過一個,列出總數以及負責人。

如果有人樂於在 python 代碼甚至 Excel 或 PowerQuery 中分享他們的邏輯,那將是一個很好的起點。 在此處輸入圖像描述

我想要實現的輸出示例:

Totals:

Randal total: 1750
Kate Total: 2100
Kevin Total: 1150

您可以在 Power Query 中執行此操作( Home=>Transform

我假設您上面的表名稱是Sales Table 如果沒有在下面代碼的Source行中進行更改。

該算法在代碼注釋中進行了概述。 但也要探索應用的步驟,看看每個步驟在做什么:

let
    Source = #"Sales Table",

//Remove unneeded columns
    #"Removed Columns" = Table.RemoveColumns(Source,{"OpportunityID", "Total Sales"}),

//Unpivot all the columns and remove the Attribute column
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Removed Columns", {}, "Attribute", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),

//We now have pairs of Rep and Split in a single column
// So add an index to group the pairs
    #"Added Index" = Table.AddIndexColumn(#"Removed Columns1", "Index", 0, 1, Int64.Type),
    #"Inserted Integer-Division" = Table.AddColumn(#"Added Index", "Integer-Division", each Number.IntegerDivide([Index], 2), Int64.Type),
    #"Removed Columns2" = Table.RemoveColumns(#"Inserted Integer-Division",{"Index"}),

//Aggregate by creating a two column table
    #"Grouped Rows" = Table.Group(#"Removed Columns2", {"Integer-Division"}, {
        {"all", each [rep=[Value]{0}, Split=[Value]{1}] }}),
    #"Expanded all" = Table.ExpandRecordColumn(#"Grouped Rows", "all", {"rep", "Split"}, {"rep", "Split"}),
    #"Removed Columns3" = Table.RemoveColumns(#"Expanded all",{"Integer-Division"}),

//Remove the "NA" reps
//then group by Rep and aggregate by Sum
    #"Filtered Rows" = Table.SelectRows(#"Removed Columns3", each ([rep] <> "NA")),
    #"Grouped Rows1" = Table.Group(#"Filtered Rows", {"rep"}, {{"Rep Total", each List.Sum([Split]), type number}})
in
    #"Grouped Rows1"

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM