Hello,
I'm trying to create a measure and at a given moment I use the following expression:
Top =
VAR Nth = 2
VAR Category = ALLSELECTED(Table[Category])
VAR Sales =
ADDCOLUMNS(
VALUES(Table[Category]),,"Rank",RANKX(Category,[Total Sales]))
VAR FilterNThCategory = FILTER(Sales , [Rank] = Nth)
VAR NthLineName = MINX(FilterNThLine,Table[Category])
VAR Subtop = CALCULATE([Total Sales],Table[Category] = NthLineName)
return Subtop
in theory the return of the variable "NthLineName" is a string, but when I use it inside the FILTER function, I don't get the expected result. However, when I replace "NthLineName" with the string "Cars", it works perfectly.
Does the FILTER function not support the use of variables or am I doing something wrong? is there any way to get around it?
thank you very much in advance
Solved! Go to Solution.
Please make a little bit change to your measure.
Top =
VAR Nth = 2
VAR Category =
ALLSELECTED ( 'Table'[Category] )
VAR Sales_ =
ADDCOLUMNS(
VALUES ('Table'[Category]),
"Rank", RANKX ( Category, [Total Sales] )
)
VAR FilterNThCategory =
FILTER(Sales_,[Rank]=Nth)
VAR NthLineName =
MINX(FilterNThCategory,'Table'[Category])
VAR Subtop =
CALCULATE ( [Total Sales], 'Table'[Category] =NthLineName)
RETURN
Subtop
Result should look like this:
Attached the pbix file as reference.
Best Regards,
Community Support Team _ Caiyun
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If you still have problems on it, please feel free to let us know. Thanks a lot!
Please make a little bit change to your measure.
Top =
VAR Nth = 2
VAR Category =
ALLSELECTED ( 'Table'[Category] )
VAR Sales_ =
ADDCOLUMNS(
VALUES ('Table'[Category]),
"Rank", RANKX ( Category, [Total Sales] )
)
VAR FilterNThCategory =
FILTER(Sales_,[Rank]=Nth)
VAR NthLineName =
MINX(FilterNThCategory,'Table'[Category])
VAR Subtop =
CALCULATE ( [Total Sales], 'Table'[Category] =NthLineName)
RETURN
Subtop
Result should look like this:
Attached the pbix file as reference.
Best Regards,
Community Support Team _ Caiyun
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If you still have problems on it, please feel free to let us know. Thanks a lot!
Does it help if you replace VALUES ( Table[Category] ) with Category?
If not, then can you provide some example data and desired results to test against?
Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.
Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!
At the monthly call, connect with other leaders and find out how community makes your experience even better.
User | Count |
---|---|
133 | |
74 | |
36 | |
25 | |
21 |
User | Count |
---|---|
139 | |
85 | |
40 | |
34 | |
22 |