Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need to filter a rankx function

Hi, 

 

I try to add a filter on my rankx function but it does not work properly.

The filter on my page is called "Year_selection", it's not a slicer but a single selection :

anneso108_0-1592817388907.png

Then the data in my report are based on the accident's year.

I want to make the link between my year_selection and the data displayed in the report. That is to say, if it is selected "2019" in the year_selection, i want my report displaying rank 1(=2019) and 2(=2018) (i have 2 different pies for current year and previous year).

For the moment, I only have the rank for accident year but it is not linked to the year_selection, it always remains on : 

anneso108_1-1592817631036.png whatever the yearname selection.

 

I would like to have this if i select 2019 :

ranking|annee|yearselected

3          |2017  |2019

2          |2018  |2019

1          |2019  |2019

 

basically, I would like to add a filter "where annee <= max_year_selected" in my rankx formula.

Here is my basic rankx formula, I've tried lots of complex one but I think it should be easier so maybe you could help me, that would be much appreciated because it makes me crazy ^^

Annee_Ranking_Lesions = RANKX(ALLSELECTED(FactSecuriteAuTravail_Lesions[Annee]),CALCULATE(max(FactSecuriteAuTravail_Lesions[Annee])))
Thanks a lot for your help, AnSo

 

 

 

4 REPLIES 4
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

Please share sample pbix file and expected output.

 

Regards,

HN

Anonymous
Not applicable

Hi HN, 

 

Thanks for your answer. However, I don't know how to share my pbix, not sure if I can because data can only be access from my company 😕 please advise if there is a way to share the model, data are not confidential, just access restricted.

But I will try to explain what I want to achieve and that makes me crazy for a few days now ^^

Here is a screen shot of my model to explain : 

anneso108_0-1593073815118.png

So I have 4 fact tables :

- SecuriteAuTravail

- FactSecuriteAuTravail_Lesions

- FactSecuriteAuTravail_Categ

- FactSecuriteAuTravail_MoyLoc

 

There is a field "Annee" in each table. There is also a field "Month" in each table but I use the filtering by month only for SecuriteAuTravail table. The 3 other fact tables are filtered on year only in the report.

 

As you can see, there is also a dimension table HierarchieService which is linked to the 4 fact tables, it is just to get hierarchy and labels of the different levels of services in the company. This one creates problem of ambiguous path, you will see in my explanations below.

 

Today, what I have in the report is : 

1/ Tabs linked to "SecuriteAuTravail", all with a synchronized date filter, one filter on year, one filter on month (period to be exact). This is done with a filter on Calendrier[AnnéeSlicer] for the year and Calendrier[PériodeSlicer] for the period of month :

anneso108_1-1593074193611.png

2/ tab linked to FactSecuriteAuTravail_Lesions where the year slicer is directly based on FactSecuriteAuTravail_Lesions[Annee]:

 

anneso108_0-1593077796820.png

 

3/ tab linked to FactSecuriteAuTravail_Categ where the year slicer is based on FactSecuriteAuTravail_Categ[Annee]

 

4/ tab linked to FactSecuriteAuTravail_MoyLoc where the year slicer is based on FactSecuriteAuTravail_MoyLoc[Annee]

 

What I would like is to have a single year filter in the report that would be synchronised between the different tabs. Or at least, keeping the date filter on year+month for SecuriteAuTravail table but having one common year filter for the 3 Lesions/Categ and MoyLoc tables.

 

As you can see in my model, I have tried to import a new calendar table (calendrier_lesionscategloco), I have also added a "numero_year" table between calendrier_lesionscategloco and my fact table to get single values for the available years : 

 

2020-06-25_10-47-35.png

 

Then I thought I could link the field Numero_year[Yearname] to each year field in my 3 fact tables, putting a bidirectional relationship.

But I can't 😕 I can only link with one fact table, then I got an error message of ambiguity for the 2nd one because of the HierarchieService table which is linked to the 4 fact tables : 

2020-06-25_10-50-28.png

 

Solving this issue would be the first step, I will then have some small issues to fix with rankx function in the report if I change my year filter (slider today) by a single selection, but when I will be fixing this, I will be happy, that would mean I have a synchronized date filter in all my tabs!  So I thought the problem should be explained in its globality before wanting to work on the rankx function, it will be in a second time.

Let me know if it's not clear and if you need more details to figure it out.

Thanks a lot for your help, AnSo

Anonymous
Not applicable

Hi amitchandak,

 

Thanks a lot for your answer. However, i've already been through many forums and tutorials, unfortunately not finding the solution to my problem. Could you be more specific to my case if possible ?


Thanks a lot, AnSo

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.