Power BI : filter on a rank - powerbi

I have calculated ranked using this formula which worked perfectly well :
RANK = RANKX(ALL(td_store[LIB_MAG]), CALCULATE(SUM(tf_market_share_by_store_nomcenclature[marche]),ALLEXCEPT(td_store,td_store[LIB_MAG])))
I have a slicer on the LIB_MAG which filter correctly my table :
However I don't want to see only the selected mag but the five previous and the last following mag, basing on the rank (in this exemple, the rank 121 to 131) like this :
Note that the rank is filtered on the LIB_RAY selected on an other slicer, so I did not succeed to pass by temporary tables ...
I tried this but it doesn't work because the RANK is a measure, not a column (it's not possible to use it in ALLEXCEPT) :
I tried this too but I don't succeed to extract the rank of the selected mag (because it's a measure again)
Have you got ideas to do this ?

Related

Setting starting and ending values of a filter

I have the a month slicer based on month number, I want to create a filter with the between format like below :
By default, when loading the report the left side will have the value of 1 (the month number of January) and the right side will have the value of the current month (the month number of October in this case)
First create a table using this below code-
month_list = GENERATESERIES(1,MONTH(TODAY()))
Now create the slicer using the Value column. Output will be as below-

Return TOP 5 values in column by category

I'm looking for good solution to be able to present on a table visual in Power BI TOP 5 highest values out of column X in table, grouped by User name in column Y of the same table.
So for each distinct user in column Y I need to show top 5 values in column X in descending order.
You can get the Top 5 details by using the RANKX function:
Rank = RANKX(CALCULATETABLE(Table,ALLEXCEPT(Table,Table[Column Y])),Table[Column X],,DESC,DENSE)
The above calculation will give you the dense rank. If you want the normal ranking use "skip" instead of "dense". Once the rank is calculated, you can filter the rank value for <=5 and you should be able to get the desired output.

( Sum Measure ) when unfiltered sum everything except 2 values

I have a card and i want it to display a sum of A-1 and A-2 and give me a value of 10 but in the same time if i selected B-2 or B-2 i should see their specific value like (4) in the card.
I can filter out the values manually in card but then, if i selected the filtered out values, the card will display a blank value.
If you want to get a simple sum.
you can just create a measure sum
Sum(Column B)
And add a slicer based on you column A.
If you select data in the slicer the sum will be automatically adapted.

How to pick up column by given parameters and then sum-up the column total in Power BI

I've got a table like below. I would like to pickup the column first by given parameters then sum up the total of the column.
For example, by given Parameter of SGD, I would like to sum-up the total amount of column SGD.
Date SO NO. AUD SGD HKD
7/1/2019 SO1 100 105.17 545.74
8/5/2019 SO2 130 122.01 691.13
9/9/2019 SO3 160 150.32 853.55
9/15/2019 SO4 180 169.11 960.25
Thanks
One way to achieve this is to add a new disconnected table Currencies with one column Currency and values AUD, SGD and HKD. Add a slicer for it and make it drop down.
Then create a measure, which will take the value of the slicer and calculate total on the corresponding column, depending on the selection in the slider:
Total = SWITCH(SELECTEDVALUE('Currencies'[Currency]; "AUD");
"AUD"; SUMX('Table'; [AUD]);
"SGD"; SUMX('Table'; [SGD]);
"HKD"; SUMX('Table'; [HKD]);
SUMX('Table'; [AUD]))
SELECTEDVALUE('Currencies'[Currency]; "AUD") will return the value selected in the slicer, or AUD if none or multiple values are selected. See SELECTEDVALUE.
SWITCH will compare this value with a list of possible options (AUD, SGD and HKD) and return corresponding expression (SUMX('Table'; [AUD]), SUMX('Table'; [SGD]) or SUMX('Table'; [HKD])), or some default value if there is no match (SUMX('Table'; [AUD])).
Then use this measure in your report, and it's value will change depending on the selection in the slicer:

Ranking a Measure Value (as opposed to a column value) in DAX?

Short version of question: how can I create a rank based on a calculated measure?
Question background:
I have a table/query that yields many rows for each employee, with each row having a time taken value.
I'd like to calculate the average time taken for each employee, and then present a table with a row for each employee, showing their name, average time taken, and rank (based on time taken).
To do the first part, I created a measure called AverageTimeLength and set it equal to:
AverageTimeLength = Average(Table_name[Column_name])
Then I coded the following:
AverageTimeLength_employee = CALCULATE([AverageTimeLength], GROUPBY(Table_name, Table_name[EmployeeName]))
These two are measures; I was able to insert the second into the new table chart I'm creating, but unfortunately, I can't use RANKX() on it because the measure values don't come from a column. If I try to create a column derived from the measure (i.e., column_name = [AverageTimeLength_employee]) I just get an error accusing column_name of circular reasoning.
What I want to do seems like it should be simple; does anyone know how I can create a simple rank parameter, to rank the measure values?
You can create the Average measure and use it in the Rank measure as follows:
Average = AVERAGE([Time taken])
Rank = IF (
HASONEVALUE ( Table_Name[Name] ),
RANKX ( ALL ( Table_Name[Name] ), [Average])
)
Hope it helps.