Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
rrjr007
Frequent Visitor

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 XApplesBrand 11
Company XApplesBrand 224794
Company XApplesBrand 33472
Company XApplesBrand 414
Company XApplesBrand 5108
Company XApplesBrand 653
Company XApplesBrand 76907

The first thing i do is calcualte what % of apples company x purchases from various brands

Company XApplesBrand 110.003%
Company XApplesBrand 22479470.141%
Company XApplesBrand 334729.822%
Company XApplesBrand 4140.040%
Company XApplesBrand 51080.306%
Company XApplesBrand 6530.150%
Company XApplesBrand 7690719.539%

Next, I create my profiles:

Advocate100%
Loyalist75% to 99%
Primary40% to 74%
Secondary11% to 39%
Tertiary5% to 10%
Trialist1% to 4%
None0%

 

My output should look like the table below.  Can I do this in power bi?  Thoughts on how?

 

Thanks in advance.

 

COMPANY FRUIT# PURCHASEDBrand 1Brand 2Brand 3Brand 4Brand 5Brand 6Brand 7
Company XApples35349NonePrimaryTertiaryNoneNoneNoneSecondary

 

1 ACCEPTED SOLUTION
v-eachen-msft
Community Support
Community Support

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.

3-1.PNG

Here is my test file for your reference.

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

 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

1 REPLY 1
v-eachen-msft
Community Support
Community Support

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.

3-1.PNG

Here is my test file for your reference.

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

 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.