Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

DAX function to show last weeks visits

Hi All

 

AIM:

Im trying to create a line graph of the weekly visits we have to our site (the summation of days of the week)

 

See image:

 

In the tooltip I aim to do two things:

1) Show the figure from last week

2) Show this figure as a percentage change

 

PROBLEM:

The formula I used in the tooltip was:

 

M % Difference = CALCULATE(SUM('Contact Us Page'[Users]),PARALLELPERIOD(tbl_Calender[Start of Week],-1,MONTH))

 

However, the Parallelperiod only breaks the time by MONTH, QUARTER and YEAR. Not Week.

 

What would be the best alternative method of achiving the AIM; so that the 04/Oct should show 855. 11/Oct should show 902 and lastly 18/Oct should show 1626 in the tooltip 

2 Replies

  • Anonymous , week can be 7 days behind

     

    7 behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-7,DAy))

     

    or with help from additional columns in date table

     

    new columns
    Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
    Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
    Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
    OR
    Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

     

    measures
    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))

     

     

    Power BI — Week on Week and WTD
    https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
    https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
    https://www.youtube.com/watch?v=pnAesWxYgJ8

  • Hi, Anonymous 

     

    May I ask if your problem has been solved? Is the above post helpful to you?

    If  it does, could you please mark the post which help as Answered? It will help the others in the community find the solution easily if they face the same problem with you. Thank you.

    If not, could you please consdier sharing more details about it or a simple sample file without any sesentive information so that we may work out with a workaround?

     

     

    Best Regards,
    Community Support Team _ Zeon Zheng

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