Forum Discussion

sw123's avatar
sw123
Icon for Helper III rankHelper III
2 years ago

Values of current week

Hi,

 

I would like to have a card showing the values (total kg) of one table, but I would like to filter it, so that it always only shows the current weeks total kg:s. Like for this week (week 9), what are the toal kg:s from monday uptil now. I have the week numbers in a date table. How do I do this?

 

Grateful for help!

4 Replies

  • sw123 , You can use relative date slicer

     

    This week using measure

     


    WTD Today =
    var _min = TODAY() -WEEKDAY(TODAY(),2) +1 //Monday week start
    var _max = today()
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

    LWTD Today =
    var _min = TODAY() -WEEKDAY(TODAY(),2) -6 //Monday week start
    var _max = today() -7
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

    LYWTD Today =
    var _max = today() -364
    var _min = _max -WEEKDAY(_max,2) +1//Monday week start
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

    WTD Yesterday =
    var _max = today() -1
    var _min = _max -WEEKDAY(_max,2) +1 //Monday week start
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

    LWTD Yesterday =
    var _max = today() -8
    var _min = _max -WEEKDAY(_max,2) +1 //Monday week start
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

    LYWTD Yesterday =
    var _max = today() -364
    var _min = _max -WEEKDAY(_max,2) +1//Monday week start
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

    This Week Today =
    var _min = today() -WEEKDAY(today() ,2) +1 //Monday week start
    var _max = _min +6
    return CALCULATE([Net], FILTER('Date','Date'[Date] >=_min && 'Date'[Date] <= _max))

     

     

    If you need based on selection have date table with following columns

    Have these new columns in Date Table, Week Rank is Important in Date/Week Table

    Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
    OR
    Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format


    These measures can help
    This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
    Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

    • sw123's avatar
      sw123
      Icon for Helper III rankHelper III

      Hi!

       

      I could use the relative slicer, but how do I get the week to start on monday and not on sunday?

       

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sw123 

     

    First of all, many thanks to amitchandak for you very quick and efficient reply, and I'll add a few things below:

     

    My sample:

     

    You can set a week to start on Monday when you calculate the week numbers.

     

    Create a calculated column as follows

    weeknum = WEEKNUM([Date], 2)

     

    When you set the second parameter in the formula to 2, it means that a week will begin on Monday. For more details about WEEKNUM function, you can read related document link: WEEKNUM function (DAX) - DAX | Microsoft Learn

     

    Then you can create a measure as follows.

    total = 
    VAR _weeknum = CALCULATE(MAX([weeknum]), FILTER('Table', [Date] = TODAY()))
    VAR _sum = CALCULATE(SUM('Table'[value]), FILTER('Table', [weeknum] = _weeknum))
    RETURN
    _sum

     

    Output:

     

    Best Regards,
    Yulia Xu

     

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

    • sw123's avatar
      sw123
      Icon for Helper III rankHelper III

      Hi,

       

      Thanks, this works otherwise, but it now calculates the sum from week 10 (this week) from every year. It means it sums up the volumes from week 10 this year with the volumes from week 10 in past years. How can I fix this?

       

      Thanks for your help!