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

Shape the future of the Fabric Community! Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions. Take survey.

Reply
Anonymous
Not applicable

Filter value based on multiple criteria

 

Hi,

Can you please help me filter value of the last year for each company in the table below?

The result in the last column should be 4 for company A, 200 for company C, and 4 for company B.

I tried to use lookupvalue, filter, and max but I couldn't figureout the arrangement in the formula.

YearValueCompanyValue in the final year
201910A 
20204A 
20215A 
20224A 
20198C 
20209C 
20217C 
2022200C 
201910B 
20204B 
20215B 
20224B 

 

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

Hi @Anonymous ,

 

Measure way:

Measure = 
VAR maxyear =
    CALCULATE ( MAX ( 'Table'[Year] ), ALLEXCEPT ( 'Table', 'Table'[Company] ) )
RETURN
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Company] ), 'Table'[Year] = maxyear )
    )

 

Alternatively,to use a calculated column as below.

in the final year = 
VAR maxyear =
    CALCULATE (
        MAX ( 'Table'[Year] ),
        FILTER ( 'Table', 'Table'[Company] = EARLIER ( 'Table'[Company] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[Year] = maxyear
                && 'Table'[Company] = EARLIER ( 'Table'[Company] )
        )
    )

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

7 REPLIES 7
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

Measure way:

Measure = 
VAR maxyear =
    CALCULATE ( MAX ( 'Table'[Year] ), ALLEXCEPT ( 'Table', 'Table'[Company] ) )
RETURN
    CALCULATE (
        MAX ( 'Table'[Value] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Company] ), 'Table'[Year] = maxyear )
    )

 

Alternatively,to use a calculated column as below.

in the final year = 
VAR maxyear =
    CALCULATE (
        MAX ( 'Table'[Year] ),
        FILTER ( 'Table', 'Table'[Company] = EARLIER ( 'Table'[Company] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            'Table',
            'Table'[Year] = maxyear
                && 'Table'[Company] = EARLIER ( 'Table'[Company] )
        )
    )

Capture.PNG

 

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
az38
Community Champion
Community Champion

Hi @Anonymous 

try a measure

 

Value in the final year= 
var _lastYear = calculate(max('Table'[Year]),ALLEXCEPT('Table','Table'[Company]))

RETURN
LOOKUPVALUE('Table'[Value], 'Table'[Company],SELECTEDVALUE('Table'[Company]), 'Table'[Year],_lastYear)

 

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi,

It gave me an Error in the SelectedValue portion. Is there a way we can fix it?
az38
Community Champion
Community Champion

Sorry @Anonymous 

it must be comma

Value in the final year= 
var _lastYear = calculate(max('Table'[Year]),ALLEXCEPT('Table','Table'[Company]))

RETURN
LOOKUPVALUE('Table'[Value], 'Table'[Company],SELECTEDVALUE('Table'[Company]), 'Table'[Year],_lastYear)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi,
Thanks for your quick reply.
The error is gone but the column now has no value in it.
Is it because PowerBI do not understand which ticker we are selecting?
FYI, The result will be used as an input for another calculation.
az38
Community Champion
Community Champion

@Anonymous 

where do yo try to see the result?

table visual based on your data sample

Безымянный.png

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

I added as a column for my current table

table.PNG

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.