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
Andrea_Jess
Helper III
Helper III

RANKX for Rolling Years

Hi All,

 

I have a disconnected date slicer that i'm using on a products graph. The graph is a line chart that returns 3 years of data based on slicer selected and it shows it by product.


For example, if i select FY21, the line graph shows FY19, FY20, and FY21 for each product. At the moment, i can see all product but i want to only show top 5 products based on the aggregated sum of Amount across the three years. When i use TOPN, i'm not getting correct products. 

 

I then thought to use RANKX but because i have a disconnected slicer, i'm not sure how to invoke it so that it ranks based on aggregated sum of past 3 years. 

The measure i'm using to filter the graph to last 3 years is: 


VAR Selected = SELECTEDVALUE(Disconnected[FiscalYear])

RETURN
IF(AND(MAX(Data[Fiscal year]) <= Selected, MAX (Data[Fiscal year] ) >- Selected-2),1,0)

 

I have applied this has a visual filter on the graph. 

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

I have created a sample pbix file based on your explanation. Instead of recent three years, I tried to created "recent three months". But the concept is the same, and I hope you can apply to your data model. Or, please share your sample pbix file, and then more accurate solution can be created.

 

Picture1.png

 

Qty total last three months: =
VAR selectedlastdate =
LASTDATE ( 'Dates Slicer'[Date] )
VAR lastthreemonth =
DATESINPERIOD ( Dates[Date], selectedlastdate, -3, MONTH )
RETURN
CALCULATE ( SUM ( Data[Qty] ), KEEPFILTERS ( lastthreemonth ) )
 
Top five products Qty total last three months: =
VAR newtable =
FILTER (
ADDCOLUMNS (
SUMMARIZE ( ALL ( Data ), Dates[Month & Year], 'Product'[Product] ),
"@lastthreemonths", [Qty total last three months:]
),
Dates[Month & Year] = VAR currentmonth = Dates[Month & Year] RETURN currentmonth
)
VAR topfiveproducts =
TOPN ( 5, newtable, [@lastthreemonths], DESC )
RETURN
CALCULATE ( [Qty total last three months:], KEEPFILTERS ( topfiveproducts ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.