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
tevisyauw
Helper I
Helper I

TopN Function on 2 column chart for This Year and Last Year

Hello everyone, please help me out with TopN Function, I am struggling for so long on measure function. 

I tried some solution from here but still not get result that I want.

I want to make 2 chart of top 5 value for selected year and last year of selected year 

Example : I select 2022 on my slicer date and i want to make 2 top N chart from this current table

NameYear Value 
A2022    1,000,000
B2022        900,000
C2022        800,000
D2022        700,000
E2022        600,000
F2022        500,000
G2022        400,000
H2022        300,000
I2022        200,000
J2022        100,000
K2022          50,000
L2022          25,000
A2021        800,000
B2021        600,000
C2021          50,000
D2021          25,000
E2021        750,000
F2021        625,000
G2021    1,000,000
H2021        950,000
I2021          10,000
J2021                  0
K2021        500,000
L2021        550,000

 

become 2 chart like this 

tevisyauw_0-1669102367574.png 

 

tevisyauw_1-1669102416130.png

 

I want to make it on measure formula because if I select on 2020 then i want my last year chart to automatically showing 2019. 

 

Thanks for your attention and appreciate any helps.

 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @tevisyauw ,

 

Here I create a sample to have a test.

Data Model:

RicoZhou_0-1669170899555.png

Measures:

Select Year Value = 
VAR _SELECTYEAR = SELECTEDVALUE(DimYear[Year])
RETURN
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = _SELECTYEAR))
Previous Year Value = 
VAR _SELECTYEAR = SELECTEDVALUE(DimYear[Year])
RETURN
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = _SELECTYEAR - 1))
Select Visual Name = "Value" &" "& SELECTEDVALUE(DimYear[Year])
Pervious Visual Name = "Value" &" "& SELECTEDVALUE(DimYear[Year])-1

Add measures in TopN filter for [Name] column.

RicoZhou_1-1669170999014.png

Add visual name measure into Title fx.

RicoZhou_2-1669171057106.png

Result is as below.

RicoZhou_3-1669171077474.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @tevisyauw ,

 

Here I create a sample to have a test.

Data Model:

RicoZhou_0-1669170899555.png

Measures:

Select Year Value = 
VAR _SELECTYEAR = SELECTEDVALUE(DimYear[Year])
RETURN
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = _SELECTYEAR))
Previous Year Value = 
VAR _SELECTYEAR = SELECTEDVALUE(DimYear[Year])
RETURN
CALCULATE(SUM('Table'[Value]),FILTER('Table','Table'[Year] = _SELECTYEAR - 1))
Select Visual Name = "Value" &" "& SELECTEDVALUE(DimYear[Year])
Pervious Visual Name = "Value" &" "& SELECTEDVALUE(DimYear[Year])-1

Add measures in TopN filter for [Name] column.

RicoZhou_1-1669170999014.png

Add visual name measure into Title fx.

RicoZhou_2-1669171057106.png

Result is as below.

RicoZhou_3-1669171077474.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Thank you so much, you are lifesaver @v-rzhou-msft just in time before my deadline. 

tevisyauw
Helper I
Helper I

need any help. appreciate it.

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.