Forum Discussion

telston's avatar
telston
New Member
5 years ago
Solved

How To Filter by Week Number

I am trying to apply a slicer to my data that would display the weeks per year all at the same time. My data has each week's data, starting Monday through Sunday in each column for 2019, 2020 and ...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi  telston ,

    Here are the steps you can follow:

    1. Enter Power query through Transform data, select [Time] column, and select Transform – Unpivot Columns – Unpivot Other Columns.

    Result:

    2. Create calculated column.

    Year = YEAR([Attribute])

    3. Create measure.

    weeknumber = CALCULATE(DISTINCTCOUNT('Table'[Attribute]),FILTER(ALL('Table'),[Year]=YEAR(SELECTEDVALUE('Table'[Attribute]))))
    2019 =
    var _day=DAY(SELECTEDVALUE('Table'[Attribute]))
    var _month=MONTH(SELECTEDVALUE('Table'[Attribute]))
    return
    CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),[Attribute]=DATE(2019,_month,_day)))
    2020 =
    var _day=DAY(SELECTEDVALUE('Table'[Attribute]))
    var _month=MONTH(SELECTEDVALUE('Table'[Attribute]))
    return
    CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),[Attribute]=DATE(2020,_month,_day)))

    4. Result:

    Use [Attribute] as a slicer to display.

    Number of weeks per year.

    Compare the data of the current selected date for all two years.

     

    Best Regards,

    Liu Yang

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