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

Display latest 3 data points in data label

Hi all,

I need to create a measure that can be used as a custom label to only show the latest n number of periods in a line chart.
The line chart displays a Year, Month, Date hierarchy, so the measure show be dynamic and display latest 3 years when on the year level, last 3 months when on the month level and latest 3 days when drilling down to days in the visualisation.

How can the measure be done?

Br.,
Thomas

1 ACCEPTED SOLUTION

Hi @thod 

You can refer to the following measure

Measure 4 = var _topyear=TOPN(3,SUMMARIZE(ALLSELECTED('Table'[Year]),[Year]),[Year],DESC)
var b=CONVERT(SELECTEDVALUE('Table'[Month]),STRING)
var c=CONVERT(SELECTEDVALUE('Table'[Date]),STRING)
return IF(ISINSCOPE('Table'[Date].[Day]),IF(CONTAINSSTRING(SELECTEDVALUE('Table'[Max date]),c),SUM('Table'[Column1]),"NA"),IF(ISINSCOPE('Table'[Date].[Month]),IF(CONTAINSSTRING(SELECTEDVALUE('Table'[Max month]),b),SUM('Table'[Column1]),"NA"),IF(SELECTEDVALUE('Table'[Year]) in _topyear,SUM('Table'[Column1]),"NA")))

Output

vxinruzhumsft_0-1688969802042.png

 

vxinruzhumsft_1-1688969812034.png

 

vxinruzhumsft_2-1688969825034.png

 

Best Regards!

Yolo Zhu

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-xinruzhu-msft
Community Support
Community Support

Hi @thod 

You can refer to the following example

Sample data 

vxinruzhumsft_0-1688707549839.png

 

1.Create two calculated column

Max month =
VAR a =
    FILTER ( 'Table', [Year] = EARLIER ( 'Table'[Year] ) )
VAR b =
    SUMMARIZE ( a, [Month] )
RETURN
    CONCATENATEX ( TOPN ( 3, b, [Month], DESC ), [Month], "," )
Max date =
VAR a =
    FILTER (
        'Table',
        [Year] = EARLIER ( 'Table'[Year] )
            && [Month] = EARLIER ( 'Table'[Month] )
    )
RETURN
    CONCATENATEX ( TOPN ( 3, a, [Date], DESC ), [Date], "," )

Then create a measure

Measure = var _topyear=TOPN(3,SUMMARIZE(ALLSELECTED('Table'[Year]),[Year]),[Year],DESC)
var b=CONVERT(SELECTEDVALUE('Table'[Month]),STRING)
var c=CONVERT(SELECTEDVALUE('Table'[Date]),STRING)
return IF(ISINSCOPE('Table'[Date].[Day]),CALCULATE(SUM('Table'[Column1]),FILTER('Table',CONTAINSSTRING([Max date],c))),IF(ISINSCOPE('Table'[Date].[Month]),CALCULATE(SUM('Table'[Column1]),FILTER('Table',CONTAINSSTRING([Max month],b))),CALCULATE(SUM('Table'[Column1]),FILTER('Table',[Year] in _topyear))))

Output

vxinruzhumsft_1-1688707838589.png

 

vxinruzhumsft_2-1688707849266.png

 

vxinruzhumsft_3-1688707858642.png

Best Regards!

Yolo Zhu

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

 

Hi Yolo Zhu,
Thanks for the reply. Not exactly what I want, or maybe I am doing it wrong.
So, when the linechart is on year and want datalabels shown for year 2023, 2022 and 2021. When you drill down to months, I want datalabels to show July, June and May.
So data labels for the latest 3 data points in the visualisation based on your selection.

Please see screendump with data from your model where I have put in "Measure" as custom data label.

Br,
Thomas2023-07-07 09_03_16-Display latest 3 data points in data label.png

Hi @thod 

You can refer to the following measure

Measure 4 = var _topyear=TOPN(3,SUMMARIZE(ALLSELECTED('Table'[Year]),[Year]),[Year],DESC)
var b=CONVERT(SELECTEDVALUE('Table'[Month]),STRING)
var c=CONVERT(SELECTEDVALUE('Table'[Date]),STRING)
return IF(ISINSCOPE('Table'[Date].[Day]),IF(CONTAINSSTRING(SELECTEDVALUE('Table'[Max date]),c),SUM('Table'[Column1]),"NA"),IF(ISINSCOPE('Table'[Date].[Month]),IF(CONTAINSSTRING(SELECTEDVALUE('Table'[Max month]),b),SUM('Table'[Column1]),"NA"),IF(SELECTEDVALUE('Table'[Year]) in _topyear,SUM('Table'[Column1]),"NA")))

Output

vxinruzhumsft_0-1688969802042.png

 

vxinruzhumsft_1-1688969812034.png

 

vxinruzhumsft_2-1688969825034.png

 

Best Regards!

Yolo Zhu

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

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.