Forum Discussion

Lucy_Ramirez's avatar
Lucy_Ramirez
Frequent Visitor
3 years ago
Solved

Last Week Value

Hello team, I need help to bring the value of last week in my dashboard. I use the following dax formula and the values are correct. Last Week Final Inventory = CALCULATE ( [FinalInventory],FILTE...
  • v-yueyunzh-msft's avatar
    3 years ago

    Hi, Lucy_Ramirez 

    Accordin to your description, you want to get the last week value by the "Year and week". 

    Here are the steps you can refer to :
    (1)This is my test data:

    (2)We need to create a 'Date' table as a dimension table:

    Date = ADDCOLUMNS( 
    CALENDAR(FIRSTDATE('Table'[Date]),LASTDATE('Table'[Date])),
    "Year", YEAR([Date]),
    "Week", weeknum([Date]),
    "Year_Week", year([Date]) * 100 + weeknum([Date])
    )

    The relationship is as belows:

    (3)Then i create a measure to sum of the value like you:

    FinalInventory = SUM('Table'[Value])

    (4)Then we can create a measure like this:

    Last Week = var _curyearweek = MAX('Date'[Year_Week])
    var _t = SUMMARIZE(ALLSELECTED('Date') , 'Date'[Year_Week] ,"Value" , [FinalInventory])
    var _maxyearweek =MAXX( FILTER( _t , [Year_Week] <_curyearweek) , [Year_Week])
    var _t2 = FILTER(_t, [Year_Week]=_maxyearweek)
    return
    MAXX(_t2,[Value])

    (5)Then we can put the measure on the visual and we can meet your need:

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

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