Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Missing values per week - return latest active value

Guys im running into a problem at work here and through hours of googling and video-watching I have yet to find the answer.   Simply put:   I have weeks with a certain price for an item. This is...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Anonymous 

    If you have a large number of weeks, you may need to use dax to build a separate week table.

    And  

     

    WeekNum = SUBSTITUTE('Price'[Week],"Week ","")

     

    Change the column type from text to whole number.

    Then build Allweek Table.

     

    AllWeek = ADDCOLUMNS(GENERATESERIES(MIN('Price'[WeekNum]),MAX('Price'[WeekNum]),1),"Week","Week"&" "&[Value])

     

    Measurez:

     

    Price = 
    VAR _P1 =
        CALCULATE (
            MAX ( 'Price'[Price] ),
            FILTER ( 'Price', 'Price'[Week] = MAX ( AllWeek[Week] ) )
        )
    VAR _MaxNum =
        MAXX (
            FILTER ( ALL ( 'Price' ), 'Price'[WeekNum] <= MAX ( AllWeek[Value] ) ),
            'Price'[WeekNum]
        )
    VAR _P2 =
        CALCULATE (
            MAX ( 'Price'[Price] ),
            FILTER ( 'Price', 'Price'[WeekNum] = _MaxNum )
        )
    RETURN
        IF ( _P1 = BLANK (), _P2, _P1 )

     

    Result:

    You can download the pbix file from this link: Missing values per week - return latest active value

     

    Best Regards,

    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.