Skip to content

Dynamic Segmentation, with Parameters

>> Download the sample (Power BI)

This sample shows the sales of the top N and bottom customers dynamically, in a standard table, a 100% bar chart and a regional donut chart.

Bottom Customer Sales Correct Total =
SUMX (
SUMMARIZE (
Products_Table,
Products_Table[Products],
"Bottom", [Bottom Customers]
),
[Bottom]
)
Bottom Customers =
CALCULATE (
[Total Sales],
TOPN (
[Total Customers] - [Customer Rank Value],
FILTER ( VALUES ( Customer_Table[Customer] ), [Total Sales] > 0 ),
[Total Sales], ASC
)
)
Top Customer Sales Correct Total =
SUMX (
SUMMARIZE ( Products_Table, Products_Table[Products], "Top", [Top Customers] ),
[Top]
)
Top Customers =
CALCULATE (
[Total Sales],
TOPN (
'Customer Rank'[Customer Rank Value],
VALUES ( Customer_Table[Customer] ),
[Total Sales], DESC
)
)
Total Customers =
COUNTROWS ( VALUES ( Sales_Table[Customer] ) )
Total Sales =
SUMX ( Sales_Table, Sales_Table[Quantity] * Sales_Table[Unit Price] )
Customer Rank Value =
SELECTEDVALUE ( 'Customer Rank'[Customer Rank] )
Calendar_Table =
GENERATE (
CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2019, 12, 31 ) ),
VAR currentDay = [Date]
VAR Day =
DAY ( currentDay )
VAR Month =
MONTH ( currentDay )
VAR Year =
YEAR ( currentDay )
RETURN
ROW ( "Day", day, "Month", month, "Year", year )
)
Customer Rank =
GENERATESERIES ( 1, 20, 1 )