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
gorsheep
Regular Visitor

Filter companies by year but keep info about other years

I have a table (see Fig. 1) with three columns: company name, year, and sales. Years range from 2019 to 2021. I want to filter only companies that have data for 2021 and show their historic sales (see Fig. 2). I tried using "Table" and "Matrix" with a filter that uses year but it removes all data for previous years. What should I do?

 

Fig. 1:

FIg 1.png

 

Fig. 2:

Fig 2.png

  

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @gorsheep 

please try

Measure1 =
VAR MaxYearWithSales =
    CALCULATE ( MAX ( TableName[Year] ), REMOVEFILTERS () )
VAR CompaniesSoldMaxYear =
    CALCULATETABLE (
        VALUES ( TableName[Company] ),
        TableName[Year] = MaxYearWithSales,
        REMOVEFILTERS ()
    )
RETURN
    CALCULATE (
        SUM ( TableName[Sales] ),
        INTERSECT ( VALUES ( TableName[Company] ), CompaniesSoldMaxYear )
    )

View solution in original post

2 REPLIES 2
tamerj1
Super User
Super User

Hi @gorsheep 

please try

Measure1 =
VAR MaxYearWithSales =
    CALCULATE ( MAX ( TableName[Year] ), REMOVEFILTERS () )
VAR CompaniesSoldMaxYear =
    CALCULATETABLE (
        VALUES ( TableName[Company] ),
        TableName[Year] = MaxYearWithSales,
        REMOVEFILTERS ()
    )
RETURN
    CALCULATE (
        SUM ( TableName[Sales] ),
        INTERSECT ( VALUES ( TableName[Company] ), CompaniesSoldMaxYear )
    )

You are truly a magician, thank you so much! Totally worked!

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.