Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

variance on Last week

  I am quite new to Power BI and currently working on the below.   I have the below table which has sales by week, I need to work out the variance between the weeks. The issue I seem to hav...
  • goncalogeraldes's avatar
    goncalogeraldes
    4 years ago

    Hello there Anonymous ! I hope the following works for you! 😅

     

     

    vs LW% = 
    VAR __previous_week =
        CALCULATE (
            SUM ( 'Appt Paste'[Sales] ),
            FILTER(
                'Appt Paste',
                YEAR ( 'Appt Paste'[Date] ) = YEAR ( TODAY() )
            ),
            DATEADD('Appt Paste'[Date], -7, DAY)
        )
    
    VAR __current_sales =
        CALCULATE (
            SUM ( 'Appt Paste'[Sales] ),
            FILTER(
                'Appt Paste',
                YEAR ( 'Appt Paste'[Date] ) = YEAR ( TODAY() )
            )
        )
    RETURN
        DIVIDE ( __current_sales - __previous_week, __previous_week, 0 )

     

     I've tested it witha  sample datset and worked for me:

     

     

    Hope this answer solves your problem!
    If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, please consider marking it as a solution ✔️ or giving it a kudoe 👍
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Gonçalo Geraldes