Forum Discussion

rrjr007's avatar
rrjr007
Frequent Visitor
6 years ago
Solved

Creating customer profiles using existing data

I'd like to use Power BI to create customer profiles based on rules.  I do this is excel and it is a huge time crucnh.  I'm hoping this is soemthing I can do. Below is my data: Company X Apples...
  • v-eachen-msft's avatar
    6 years ago

    Hi rrjr007 ,

     

    Here are two ways.

    1.Use DAX

    Per = 
    DIVIDE('Table'[# PURCHASED],CALCULATE(SUM('Table'[# PURCHASED]),ALLSELECTED('Table')))
    Sum =
    CALCULATE(SUM('Table'[# PURCHASED]), ALLSELECTED('Table'))

    Then you could use IF() function to show final results.

    2. Use m query
    Open advance editor, and refer to the following m query:

    let
        Source = Your source,
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", Int64.Type}}),
        Custom1 = #"Changed Type",
        #"Renamed Columns" = Table.RenameColumns(Custom1,{{"Column1", "Company"}, {"Column2", "Fruit"},{"Column3", "Brand"},{"Column4", "# PURCHASED"}}),
        #"Grouped Rows" = Table.Group(#"Renamed Columns", {"Fruit"}, {{"Count", each List.Sum([#"# PURCHASED"]), type number}, {"sum", each _, type table [Company=text, Fruit=text, Brand=text, #"# PURCHASED"=number]}}),
        #"Expanded sum" = Table.ExpandTableColumn(#"Grouped Rows", "sum", {"Company", "Fruit", "Brand", "# PURCHASED"}, {"sum.Company", "sum.Fruit", "sum.Brand", "sum.# PURCHASED"}),
        #"Added Custom" = Table.AddColumn(#"Expanded sum", "Custom", each if
    [#"sum.# PURCHASED"]/[Count] >=0.01 
    and
    [#"sum.# PURCHASED"]/[Count] <0.05
    then
    "Trialist"
    else if 
    [#"sum.# PURCHASED"]/[Count] >=0.05 
    and
    [#"sum.# PURCHASED"]/[Count] <0.11
    then
    "Tertiary"
    else if 
    [#"sum.# PURCHASED"]/[Count] >=0.11 
    and
    [#"sum.# PURCHASED"]/[Count] <0.4
    then
    "Secondary"
    else if 
    [#"sum.# PURCHASED"]/[Count] >=0.4 
    and
    [#"sum.# PURCHASED"]/[Count] <0.75
    then
    "Primary"
    else if 
    [#"sum.# PURCHASED"]/[Count] >=0.75 
    and
    [#"sum.# PURCHASED"]/[Count] <0.99
    then
    "Loyalist"
    else if 
    [#"sum.# PURCHASED"]/[Count] = 1
    then
    "Advocate"
    else 
    "None"),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"sum.# PURCHASED"}),
        #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[sum.Brand]), "sum.Brand", "Custom")
    in
        #"Pivoted Column"

    Here is the result.

    Here is my test file for your reference.

    Table is created by DAX, Table2 is created by m query.