Forum Discussion

emildeak's avatar
emildeak
Regular Visitor
3 years ago
Solved

Grouped by week - determine change

Hi,   i have a problem where i stuck since several days, maybe you can help me.   I have a table with 2 columns, day and value. I'd like to get the value grouped bei a week Starting on Monday. A...
  • v-jianboli-msft's avatar
    3 years ago

    Hi emildeak ,

     

    Based on your description, I have created a simple sample:

    Please try:

    Week Avg = 
    var _a = WEEKDAY(MAX('Table'[Day]),2)
    var _b = CALCULATE(AVERAGE('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)))
    return IF(_a=7,_b)
    
    Weekly Change = 
    var _a = WEEKDAY(MAX('Table'[Day]),2)
    var _b = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)))// the value of current week
    var _c = CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),WEEKNUM([Day],2)=WEEKNUM(MAX('Table'[Day]),2)-1))// the value of previous week
    var _d = DIVIDE(_c,_b)
    return IF(_a=7,_d)

    Output:

    Since I'm not sure what your weekly change is based on, I calculated the percentage change in their total weekly value. You can change the aggregation in the measure to get the value you want, or clarify your calculation logic to me.

     

    Best Regards,

    Jianbo Li

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