Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi
I have a table with multiple years, customers, and products (along with some other metrics such as country, age, etc). I would like to find out how many unique products each customer bought each year. I will then split this by country, age etc.
First, I don't know whether it's better to create a new table or measures? Probably measures?
I wanted to use this solution, but it only counts the number of occurences - I need a number of occurences of unique products for each unique customer, but then also filtered for each year.
Can someone please help?
Hi @lalala932
Please create a proper star-schema model for this unless you want to face issues impossible to resolve in a one-table model (speaking from experience) later on.
Here's some mandatory reading for all Power BI aspiring adepts: Understand star schema and the importance for Power BI - Power BI | Microsoft Docs
Once you've got a proper model, then you can start writing DAX. Not the other way round. The measure will be something along these lines:
// Say that you've got the following dimensions:
// Customers, Products, Dates (the date table in the model).
// You also have a fact table that these join to.
// Fact table should always have its all columns hidden,
// apart from degenerate dimensions (which you I believe
// don't have anyway).
[# Unique Prods Bought] = DISTINCTCOUNT( FactTable[ProductID] )
// This simple measure looks at the fact table
// (where there's a key to the Products dimension)
// and returns the number of distinct keys that are
// visible in the current context. If you start slicing
// and dicing your model by dimensions, it'll adjust
// automatically to the selections. So, if you, say,
// select a year from your Dates table and a customer
// from Customers, it'll return the number of distinct
// products bought by the customer in the very year.
User | Count |
---|---|
22 | |
11 | |
8 | |
6 | |
6 |
User | Count |
---|---|
25 | |
12 | |
11 | |
7 | |
6 |