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
dphillips
Helper IV
Helper IV

Filter data using last value in a table

I have some values and I find the average of these values over a field called YearSemImage1.JPG

 

 

I use a line graph to visualise this. See below.

 

How can I pick out the last value (3.49) and put it into a card?

At the moment I find the last value in the YearSem column by creating this measure:

 

Last LP Period = CALCULATE(MAX(AveLPs[YearSem]))

This works and I get a value which is 2017 (T4).

 

Then I use this in a measure like this:

 

 

Last LP Ave = CALCULATE(AVERAGE(AveLPs[AveLP]),FILTER(AveLPs,AveLPs[YearSem]=[Last LP Period]))

 

However, I still get the average for all the years (3.58), NOT that last value (3.49) when I put this measure into a card.

 

Image2.JPG

 

 

 

 

 

 

 

 

 

 

What am I doing wrong? Any help would be appreciated.

1 ACCEPTED SOLUTION

This would also work.  The issue with your query is when you bring a calculated measure through to the CALCULATE you change the filter context (which sometimes is what you want - but not in your case)

 

Last LP Ave = 
    CALCULATE(
            AVERAGE(AveLPs[Average of AveLP]),
            FILTER(AveLPs,AveLPs[YearSem]=MAX(AveLPs[YearSem]))
            )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

3 REPLIES 3
Phil_Seamark
Employee
Employee

Hi @dphillips

 

You have a filter context problem that can be solved by re-arranging your measure to be as follows

 

Last LP Ave = 
var d = CALCULATE(MAX(AveLPs[YearSem]))
return 
    CALCULATE(
            AVERAGE(AveLPs[Average of AveLP]),
            FILTER(AveLPs,AveLPs[YearSem]=d))

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Brilliant - thanks for your help

This would also work.  The issue with your query is when you bring a calculated measure through to the CALCULATE you change the filter context (which sometimes is what you want - but not in your case)

 

Last LP Ave = 
    CALCULATE(
            AVERAGE(AveLPs[Average of AveLP]),
            FILTER(AveLPs,AveLPs[YearSem]=MAX(AveLPs[YearSem]))
            )

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.