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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.