Forum Discussion

Narasimha's avatar
Narasimha
Helper I
9 years ago

Last 4 weeks data on line chart

Hi,

 

I have data like below.. I want to display Last 4 weeks dataat any time. and week starts from monday..

i was created week using below dax

week=concate("Week-",datetable(date),2)

 

Week    ticketsCount
-----------------------
Week1    10
week2    20
week3    29
week4    28
week5    50
week6    20

could you please help me on it

 

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    I would create another Week column, perhaps WeekNum with only the number, then you could use a filter of <=4.

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    Narasimha wrote:

    Hi,

     

    I have data like below.. I want to display Last 4 weeks dataat any time. and week starts from monday..

    i was created week using below dax

    week=concate("Week-",datetable(date),2)

     

    Week    ticketsCount
    -----------------------
    Week1    10
    week2    20
    week3    29
    week4    28
    week5    50
    week6    20

    could you please help me on it

     


    Narasimha

    You may need a calendar table as below. Then you can get the Last X weeks for any given date by using the weeksequence column.

    calendar =
    VAR temptable =
        ADDCOLUMNS (
            CALENDAR ( "2016-12-01", "2018-12-31" ),
            "Monday", [Date] - WEEKDAY ( [Date] )
                + 2
        ) //get every week's Monday
    RETURN
        ADDCOLUMNS (
            temptable,
            "WeekSequence", RANKX ( temptable, [Monday],, ASC, DENSE )
        )