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
nasilemak06
New Member

FILTER ignore Measure

Hi

I have a dynamic week table lookup:


Start_week
==
1
2
3
4 <--- This is current week


I have a transaction table (weekly_files) with Week as transaction date from previous week


Start_Week Product Quantity
1 TV 10
1 Laptop 5
2 TV 1
2 Laptop 1
3 Laptop 3


I am able to get latest week with the below:

Start Week: 0 = CALCULATE(MAX(dynamic_calendar_lookup[start_week]), FILTER(weekly_files, weekly_files[quantity] <> BLANK()))

This returns 3


Now I want to see ONLY Latest week (W3), so I am creating a new measure "Request W0"

 

Case 1: Re-using the measure "start week: 0"

Request W0 = CALCULATE([Quantity - Total], FILTER(dynamic_calendar_lookup,dynamic_calendar_lookup[start_week] = [Start Week: 0]))

I am getting all weeks returns

 

start_week Request W0
1 15
2 2
3 3

 

Case 2: Not using the measure "start week: 0", but instead I am using the reference of the week

Request W0 = CALCULATE([Request - Total], FILTER(dynamic_calendar_lookup,dynamic_calendar_lookup[start_week] = 3))

 

I am getting what I want

 

start_week Request W0
3 3

 

How to make my measure (Request W0) working with the previous measure (Start Week: 0)?

Cheers
L.

1 ACCEPTED SOLUTION
AlB
Super User
Super User

@nasilemak06 

Request W0 =
VAR startW_ = [Start Week: 0]
RETURN
    CALCULATE (
        [Quantity - Total],
        FILTER (
            dynamic_calendar_lookup,
            dynamic_calendar_lookup[start_week] = startW_
        )
    )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

View solution in original post

3 REPLIES 3
AlB
Super User
Super User

@nasilemak06 

To avoid context transition interacting with your measure. Note that when you invoke the measure from within FILTER(), there exists a row context that will trigger context transition, that in turn will apply a filter context to your measure when being executed. By invoking the measure at the beginning, outside FILTER() and without a row context present, you avoid that context transition; the measure will yield the same result as when invoked in a visual card, which is what you were looking for. Then, you use that result (immutable after being stored in a variable)  in the FILTER () operation.

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

AlB
Super User
Super User

@nasilemak06 

Request W0 =
VAR startW_ = [Start Week: 0]
RETURN
    CALCULATE (
        [Quantity - Total],
        FILTER (
            dynamic_calendar_lookup,
            dynamic_calendar_lookup[start_week] = startW_
        )
    )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Thanks @AlB  it works like a charm. Can you please explain why I need to put my measure in a variable? Sorry, I am new in Power Bi

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.