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
Lars_Denmark
Frequent Visitor

Filter matrix by RankX measure

I have a sales table with customers and their revenue and date.


For the X customers with the largest revenue measured over the whole year, I will create a matrix sorted by year, quarter and month, showing the X customers and their revenue in descending order within the month.

 

I have tried unsuccessfully to create the matrix using the solution in this link to another user's previous question:

Filter "Top N" by a measure 

 

I use this measure to filter and select the customers with the highest revenue for the year:

 

Lars_Denmark_1-1712227621719.png

 

My problem is, this measure marks customers with the largest turnover in the month, where I want the customers with the largest turnover for the whole year to be selected.

 

In the example below, I have chosen to see only the 2 customers with the largest turnover in the year, which are customer I and E, but in the matrix other customers are also shown as their revenue is larger in the month.

 

Lars_Denmark_5-1712231082340.png

 

In this situation, how to get Power BI to show the matrix only with customer I and E?

 

I expected to see these amounts for the chosen months (made in Excel):

Lars_Denmark_6-1712231287743.png

If I choose to view 3 customers, customer I, E and C should be displayed ...

I would like to use the solution to display a line chart for the selected X customers.

 

My PBIX file can be downloaded from Wetransfer with this link: https://we.tl/t-yCV0LLNj6H 

 

Any help greatly apprecaited!

1 ACCEPTED SOLUTION

Hi @Lars_Denmark ,

 

Create the following measures:

Total Revenue for top customers = 
VAR _temptable = ADDCOLUMNS(
		VALUES('DummyData'[Customer]),
		"rank", [Ranking Measure]
	)
	RETURN
		SUMX(
			FILTER(
				'DummyData',
				'DummyData'[Customer] IN SELECTCOLUMNS(
					FILTER(
						_temptable,
						[rank] <> BLANK()
					),
					"d",
					'DummyData'[Customer]
				)
			),
			[Revenue Measure]
		)

% Over Total = DIVIDE([Total Revenue for top customers], [Revenue Measure])

MFelix_0-1712592326966.png

File attach.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @Lars_Denmark ,

 

Try the following code:

 

Total Revenue Year = CALCULATE(
		[Revenue Measure],
		ALL('DummyData'),
		VALUES('DummyData'[Customer])
	)

Ranking Measure = 
	VAR _ranking = RANKX(
		ALL('DummyData'[Customer]),
		[Total Revenue Year]
	)
	RETURN
		IF(
			[Revenue Measure] <> BLANK() && _ranking <= [Parameter Value],
			_ranking
		)

 Result below and in attach file:

MFelix_0-1712330659599.png

The formula may need some adjustments for the year values since you only have one year of data in the sample but the base is the same.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix, many thanks for this solution and it actually gives the result I asked for.

 

Based on the table, I have now tried to create a corresponding clustered column chart with the filter Ranking Measure <> Blank , which shows the revenue per month for the selected customers, but I don't think I can make it work when I don't include the customers in the chart.

 

I would therefore like to ask if you have the opportunity to also show how I can get such a line and clustered column chart to show the revenue in columns for, for example, the 3 ranked customers, where Jan = 665, Feb = 2431, Mar = 640

 

and on the line, I want to show the 3 customers' revenue as a percentage of the month's total revenue for all customers (2nd y-axis)

Hi @Lars_Denmark ,

 

Create the following measures:

Total Revenue for top customers = 
VAR _temptable = ADDCOLUMNS(
		VALUES('DummyData'[Customer]),
		"rank", [Ranking Measure]
	)
	RETURN
		SUMX(
			FILTER(
				'DummyData',
				'DummyData'[Customer] IN SELECTCOLUMNS(
					FILTER(
						_temptable,
						[rank] <> BLANK()
					),
					"d",
					'DummyData'[Customer]
				)
			),
			[Revenue Measure]
		)

% Over Total = DIVIDE([Total Revenue for top customers], [Revenue Measure])

MFelix_0-1712592326966.png

File attach.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.