I have a table of data, and I want to sort by STATE, and then for each STATE, return the TopN (say Top 3 for example) COMPANY per state.
Using the generic visual filter for Top 3 Company, by Value, will not quite do what I need. Using that will check for all states, get the top 3 companies, and then return those for each state.
I am trying to return the top 3 companies per state.
State Company Type Amount
CA A Crystal 100
CA A Crystal 200
CA B Crystal 3
CA C Felt 500
CA D Felt 300
NV A Rock 10
NV F Stone 900
NV Z Stone 1000
TX A Crystal 20
TX B Crystal 10
TX F Rock 400
TX F Rock 30
RI A Glass 40
RI A Glass 20
RI A Glass 2000
RI C Stone 300
Expected Output (done in Excel, but it would be a Matrix in PowerBI):

So far, I have tried this but I'm not quite sure what it's doing. I added to the visual filter, to show values less than 4, but it doesn't return what I'm trying to return. The below is entered as a New Column (not Measure):
State Company Rank = Var thisGroup = DataTable[State]
RETURN
Rankx(
Filter(
DataTable,
DataTable[State] = thisGroup
),
DataTable[Amount],
,
,
Dense
)
Note that I have an additional column in there ("type") that I add in "under" the State->Company. I didn't include here as I don't know if that affects any measures/DAX needed.
