Forum Discussion

nasilemak06's avatar
nasilemak06
New Member
5 years ago
Solved

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.

  • 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 

     

3 Replies

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    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 

     

    • nasilemak06's avatar
      nasilemak06
      New Member

      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

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    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