Forum Discussion
rohit91
2 years agoNew Member
Customer's Nearest Neighbours by Revenue
Hi Experts!! I've one question regarding finding nearest 4 neighbours of Customer by revenue and displaying them in the same text box. It could be neighbour who have revenue just more than the s...
- 2 years ago
Hi,
I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
WINDOW function (DAX) - DAX | Microsoft Learn
expected result select: = VAR _Slicer = MAX ( 'Customer slicer'[Customer Name] ) VAR _T = ADDCOLUMNS ( ALL ( Data[Customer ID], Data[Customer Name] ), "@Revenue", [Revenue total:], "@SelectedRevenue", CALCULATE ( [Revenue total:], Data[Customer Name] = _Slicer, REMOVEFILTERS () ) ) VAR _Diff = FILTER ( ADDCOLUMNS ( _T, "@Diff", ABS ( [@Revenue] - [@SelectedRevenue] ) ), Data[Customer Name] <> _Slicer ) VAR _NearestCustomer = SUMMARIZE ( WINDOW ( 1, ABS, 4, ABS, _Diff, ORDERBY ( [@Diff], ASC ) ), Data[Customer Name] ) RETURN CONCATENATEX ( FILTER ( Data, Data[Customer Name] IN _NearestCustomer ), Data[Customer Name], " ," )
Jihwan_Kim
Super User
2 years agoHi,
I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.
Please check the below picture and the attached pbix file.
WINDOW function (DAX) - DAX | Microsoft Learn
expected result select: =
VAR _Slicer =
MAX ( 'Customer slicer'[Customer Name] )
VAR _T =
ADDCOLUMNS (
ALL ( Data[Customer ID], Data[Customer Name] ),
"@Revenue", [Revenue total:],
"@SelectedRevenue", CALCULATE ( [Revenue total:], Data[Customer Name] = _Slicer, REMOVEFILTERS () )
)
VAR _Diff =
FILTER (
ADDCOLUMNS ( _T, "@Diff", ABS ( [@Revenue] - [@SelectedRevenue] ) ),
Data[Customer Name] <> _Slicer
)
VAR _NearestCustomer =
SUMMARIZE (
WINDOW ( 1, ABS, 4, ABS, _Diff, ORDERBY ( [@Diff], ASC ) ),
Data[Customer Name]
)
RETURN
CONCATENATEX (
FILTER ( Data, Data[Customer Name] IN _NearestCustomer ),
Data[Customer Name],
" ,"
)