0

We are trying to create a model in Excel/Power BI (using Power Query or Power Pivot or anything that would work) in order to classify a customer by its best product (based on a ranking system).

The first approach we applied was to count the customers per minimum ranking (or per best product brand). (inspired from the blog https://stackoverflow.com/questions/15742186/powerpivot-dax-dynamic-ranking-per-group-min-per-group)

Below the steps we did exactly: - In PowerPivot Model, we created Classification and Customers table like in the example further below.

  • In the same model, we added a calculated column with the following formula to obtain the minimum rank per customer.

    =MINX (
    FILTER ( ALLSELECTED ( Customers ); [Customer_ID] = EARLIEST ( [Customer_ID] ) );
    [Ranking]
    )
    
  • Within a pivot table in Excel, we’ve put the calculated column in rows.

  • Then, we’ve used a Count distinct aggregation of the customers in the pivot table values.  This gave me the first desired result. (below example Pivot_Table.Selection1)

Now, the issue comes when we want to add more analysis axis. For example, besides the product brand, we want to have the Product type in columns, and we want our measure to be recalculated every time I add/delete an axis. In other words, we want to have a distinct customer count per best product and per Product Type. In addition, we want the second attribute (axis) to be variable and the grouping or the distinct count per group to be dynamic.

Example:

Let’s suppose we have the tables Classification and Customers in our Model:

enter image description here enter image description here

In the first approach we tried, we got the following table: Pivot_Table.Selection1:

enter image description here

Now when we add the analysis axis, we would like to have the following example: Pivot_Table.Selection2:

enter image description here

But we are having this:

enter image description here

As you can see, there should be one customer for the Group “Mercedes” and one for “Renault”, since depending on the product type, the top Truck for customer A is Renault and its top Car is “Mercedes”. However, in the pivot table, the Mercedes group is shown as Truck (which doesn’t even exist in our dataset).

enter image description here

Edit

I'm open for any suggestion, not only Power Pivot, but also Power Query (M functions) or Power BI or whatever could work.

halfer
  • 19,824
  • 17
  • 99
  • 186
Rami Ouanes
  • 21
  • 1
  • 5
  • I am trying to say hello but stackoverflow isn't appreciating us saying hello :D. – Rami Ouanes Feb 09 '17 at 11:22
  • the issue is related to the measure you are using, are you using the default distinct count in pivot table or have you created a measure for that? – alejandro zuleta Feb 09 '17 at 15:31
  • Hello, I am actually using the default distinct count. Are you saying I need to create the measure in the powerpivot directly? – Rami Ouanes Feb 09 '17 at 16:25
  • Yes, default distinct count measure will take in account each customer id in the given context of the pivot. – alejandro zuleta Feb 09 '17 at 16:37
  • Hello Alejandro, I have tried creating a distinct count measure in the PowerPivot model but it's still not working, the issue is that now it's showing "Renault" even if I don't add the "Product Type" in columns... So it's still not refreshing the calculation but this time not even for the first axis which is the static axis in my need. – Rami Ouanes Feb 10 '17 at 08:57
  • I've recreated your tables and when I add Customer_ID in values and set a distinct count it shows values correctly. Try creating the pivot again without any filter or slicer on it. – alejandro zuleta Feb 10 '17 at 13:20
  • I'm probably missing something, but even by recreating the pivot in a new Excel File, it's still not working. Here's the [Template](https://drive.google.com/file/d/0B50nOwK8gaJbblBTTHFaaTVyaWs/view?usp=sharing) I'm using – Rami Ouanes Feb 10 '17 at 14:55
  • Are you using Product_Brand from Classification table or Customer table? – alejandro zuleta Feb 10 '17 at 15:13
  • I'm doing a lookup on the product brand in the Customer Table corresponding to the calculated column (min ranking per customer). – Rami Ouanes Feb 10 '17 at 15:18
  • I mean which product_brand are you using in the Pivot table? – alejandro zuleta Feb 10 '17 at 15:21
  • I am not using the classification table at all. I am using a column that I calculated containing a lookup on the Product_Brand from the Customers Table that corresponds to the other calculated column which is the Minimum Ranking per customer. So in other words, if my min Ranking for the customer A equals 3, I put MERCEDES in the new calculated column. – Rami Ouanes Feb 10 '17 at 15:55
  • It seems the issue is related to the rank, Is it ok Renaul has a rank of 3 in the third row? How do you calculate `Min_Product_Type_Per_Customer` calculated column?. – alejandro zuleta Feb 10 '17 at 18:45
  • Alejandro, actually that was a typo, I have fixed that in the template I have sent you and still it's not showing the correct result... the Min_Product_Type_Per_Customer is calculated using the following formula: `LOOKUPVALUE([Product_Brand];[Ranking];[Min_Ranking_Per_Customer])` – Rami Ouanes Feb 13 '17 at 09:10
  • I think your problem is `Min_Product_Type_Per_Customer` calculated column that you are using in the Row Labels pane. If you use `Product_Brand` instead of `Min_Product_Type_Per_Customer` this is what I get [Image](http://i.imgur.com/cjyMJH4.png). Without knowing the expression for `Min_Product_Type_Per_Customer` there is no much we can do in order to identify the issue. – alejandro zuleta Feb 13 '17 at 13:19
  • Alejandro, as per my last comment, the expression for the `Min_Product_Type_Per_Customer` is : `LOOKUPVALUE([Product_Brand];[Ranking];[Min_Ranking_Per_Custo‌​mer])` . When putting the Product_Brand in lines it does give the correct PivotTable when putting the `Product_Type` in the columns. But when you delete the `Product_Type` from the columns, you won't have the correct Pivot Table. In other words, try taking away the `Product_Type` from the columns and you won't have a table as the one from my example : `PivotTable.Selection1`. It looks like it's not calculating the min.. – Rami Ouanes Feb 13 '17 at 18:04

1 Answers1

1

Finally I think I understood your problem, a customer can have different Product_Brand values, you want to count only those Product_Brand which its ranking is the minimum.

In that case, this is a possible solution:

Create a calculated column called Minimum Rank in the Customer table.

=
CALCULATE (
    MIN ( [Ranking] );
    FILTER ( Customer; [Customer_ID] = EARLIER ( Customer[Customer_ID] ) )
)

Then create a measure, lets say Customer ID Distinct Count to count those rows where the Rank is equal to the minimum for that customer.

Customer ID Distinct Count :=
CALCULATE (
    DISTINCTCOUNT ( Customer[Customer_ID] );
    FILTER ( Customer; [Ranking] = [Minimum Rank] )
)

You will get something like this:

enter image description here enter image description here

halfer
  • 19,824
  • 17
  • 99
  • 186
alejandro zuleta
  • 13,962
  • 3
  • 28
  • 48
  • @RamiOuanes, You're welcome. If my answer solved your question you can select it as the correct answer. [How to select an answer as correct](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) – alejandro zuleta Feb 15 '17 at 16:43