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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
lcfaria
Helper II
Helper II

Trying to filter the results to show just the last week of my last year

Hi all, I need help.

 

I have a simple table with the following columns:

lcfaria_0-1648407320348.png

So I created a measure to calculate what my max year is and what my max week is, and then do a distinct count of my managers. I also applied a filter to bring only ratings equal to Bad, Medium or Good.

lcfaria_1-1648407841811.png

As example, for week 7 2020, I have this result (2 distinct managers):

lcfaria_2-1648407931102.png

However, when I use this on a card, and I apply a filter only for rate "Good", the result should be 0 (because I don't have any manager with rate "Good" for week 7 2020), but on my card the result returned is being 2.

lcfaria_3-1648407994361.png

In a table, values are also being returned for other weeks and not just week 7 2020.

lcfaria_4-1648408031834.png

I don't know where I'm going wrong and would like some help from the community.

PS: I don't have a calendar table and I don't want to use it for this specific case.

 

Here is the link to this file: https://1drv.ms/u/s!At5JlMR_naI1gf4wTW_SSm3pNmwSSA

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@lcfaria 

In the matrix you were running into problems with the filter context for when the variables are calculated and in the card it was CALCULATE reading 'Fact'[Rating] in {"Bad","Medium","Good"}) that was ignoring your filter.  We can fix these with some ALL and KEEPFILTERS.

Measure = 
VAR MaxYear = CALCULATE ( MAX('Fact'[Year]), ALL ('Fact') ) -- This correctly returns the last year (Year 2020)
VAR MaxWeek = 
CALCULATE(
    MAX('Fact'[Week]),
    ALL('Fact'),
    'Fact'[Rating] in {"Bad","Medium","Good"},
    'Fact'[Year] = MaxYear
) -- This correctly returns the last week of the year (Week 7)
VAR Result =
CALCULATE(
    DISTINCTCOUNT('Fact'[Manager]),
    KEEPFILTERS('Fact'[Rating] in {"Bad","Medium","Good"}),
    KEEPFILTERS('Fact'[Week] = MaxWeek),
    KEEPFILTERS('Fact'[Year] = MaxYear)
)
RETURN
Result

jdbuchanan71_0-1648411572704.png

 

 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@lcfaria 

In the matrix you were running into problems with the filter context for when the variables are calculated and in the card it was CALCULATE reading 'Fact'[Rating] in {"Bad","Medium","Good"}) that was ignoring your filter.  We can fix these with some ALL and KEEPFILTERS.

Measure = 
VAR MaxYear = CALCULATE ( MAX('Fact'[Year]), ALL ('Fact') ) -- This correctly returns the last year (Year 2020)
VAR MaxWeek = 
CALCULATE(
    MAX('Fact'[Week]),
    ALL('Fact'),
    'Fact'[Rating] in {"Bad","Medium","Good"},
    'Fact'[Year] = MaxYear
) -- This correctly returns the last week of the year (Week 7)
VAR Result =
CALCULATE(
    DISTINCTCOUNT('Fact'[Manager]),
    KEEPFILTERS('Fact'[Rating] in {"Bad","Medium","Good"}),
    KEEPFILTERS('Fact'[Week] = MaxWeek),
    KEEPFILTERS('Fact'[Year] = MaxYear)
)
RETURN
Result

jdbuchanan71_0-1648411572704.png

 

 

@jdbuchanan71 this worked exactly as expected, thank you very much!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.