cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
LiamReidy
New Member

Forecast vs Actual Line Graph for current week or month

Hi Community!

 

I have set targets for calories consumed on a daily basis over the course of a week/month. I want to view this as a cumulative line graph against the actual amount of calories i have consumed (budget vs actual).

 

I have created 2 views on power bi using the following tables as data sources:


Table 1

DayDate

Calorie

Target

Calorie

Acutal

Sunday22/03/202020003000
Monday23/03/202020002500
Tuesday24/03/202020002064
Wednesday25/03/202020002200
Thursday26/03/202020002096
Friday27/03/202020001939
Saturday28/03/202020002005
Sunday29/03/202020002295
Monday30/03/202020002050
Tuesday31/03/202020002282
Wednesday01/04/202020002044
Thursday02/04/202020002029
Friday03/04/202020002112
Saturday04/04/202020002193
Sunday05/04/202020002500
Monday06/04/202020003000

 

Line Graph A: which uses column C&D from table 1 above

Calorie Tracker Current View.pngCurrent View using Table 1

 

TABLE 2

DayDate

Calorie

Target

Calorie

Actual

Sunday22/03/202020003000
Monday23/03/202020002500
Tuesday24/03/202040004564
Wednesday25/03/202060006764
Thursday26/03/202080008860
Friday27/03/20201000010799
Saturday28/03/20201200012804
Sunday29/03/20201400015099
Monday30/03/202020002050
Tuesday31/03/202040004332
Wednesday01/04/202060006376
Thursday02/04/202080008405
Friday03/04/20201000010517
Saturday04/04/20201200012710
Sunday05/04/20201400015210
Monday06/04/202020003000

 

 Line graph B which uses columns C&D from table 2 above

Calorie Tracker Desired View.pngCurrent View using Table 2

 

DESIRED OUTCOME: 

I want to have a view such as seen by the Line Graph B that draws data from Table 1, instead of Table 2 . How do i make Table 1 a cumulative line graph?

I also want to be able to view only the current weeks or months data, starting at only the first day of the week or month. 

(if it is wednesday, i want to see my forecast calories from the last Monday through to sunday against the actual calories i have consumed so far (Monday-Wednesday) to give me a quick view to see if i am on track to meet my weekly goal.

 

Please feel free to point me in the direction of other answers.

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: Forecast vs Actual Line Graph for current week or month

HI @LiamReidy,

#1, You can use the following measure formulas to calculate rolling WTD actual or target based on date field:

WTD Acutal = 
VAR currDate =
    MAX ( Test[Date] )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Acutal] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( currDate, 2 )
                && [Date] <= currDate
        )
    )

WTD Target = 
VAR currDate =
    MAX ( Test[Date] )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Target] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( currDate, 2 )
                && [Date] <= currDate
        )
    )

#2, I think you need to create a new table with date field which not has a relationship to current table records, then you can use it as the source field on slicer to interact new measures formulas:

Selected PWTD Target =
VAR currDate =
    MAX ( Selector[Date] )
VAR prevWeekEnd =
    currDate - WEEKDAY ( currDate, 2 )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Target] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( prevWeekEnd )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( prevWeekEnd, 2 )
                && [Date] <= prevWeekEnd
        )
    )


Selected WTD Actual=
VAR currDate =
    MAX ( Selector[Date] )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Actual] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( currDate, 2 )
                && [Date] <= currDate
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

3 REPLIES 3
Super User IV
Super User IV

Re: Forecast vs Actual Line Graph for current week or month

@LiamReidy, In this file I have created WTD using rank and weekday. I think same should work for you in this cae

https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

 

Does the above reply helps. if you need more help mrke me @

Appreciate your Kudos.





Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
In case it does not help, please provide additional information and mark me with @
My Recent Blog -Week is not so Weak Proud to be a Super User! Connect on Linkedin


Community Support
Community Support

Re: Forecast vs Actual Line Graph for current week or month

HI @LiamReidy,

#1, You can use the following measure formulas to calculate rolling WTD actual or target based on date field:

WTD Acutal = 
VAR currDate =
    MAX ( Test[Date] )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Acutal] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( currDate, 2 )
                && [Date] <= currDate
        )
    )

WTD Target = 
VAR currDate =
    MAX ( Test[Date] )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Target] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( currDate, 2 )
                && [Date] <= currDate
        )
    )

#2, I think you need to create a new table with date field which not has a relationship to current table records, then you can use it as the source field on slicer to interact new measures formulas:

Selected PWTD Target =
VAR currDate =
    MAX ( Selector[Date] )
VAR prevWeekEnd =
    currDate - WEEKDAY ( currDate, 2 )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Target] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( prevWeekEnd )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( prevWeekEnd, 2 )
                && [Date] <= prevWeekEnd
        )
    )


Selected WTD Actual=
VAR currDate =
    MAX ( Selector[Date] )
RETURN
    CALCULATE (
        SUM ( Test[Calorie Actual] ),
        FILTER (
            ALLSELECTED ( Test ),
            YEAR ( [Date] ) = YEAR ( currDate )
                && WEEKNUM ( [Date], 2 ) = WEEKNUM ( currDate, 2 )
                && [Date] <= currDate
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

LiamReidy
New Member

Re: Forecast vs Actual Line Graph for current week or month

@amitchandak @v-shex-msft  Thank you both! i will try both your suggestions and feedback to you later on 🙂

Helpful resources

Announcements
Announcing the New Spanish Forum

Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

‘Better Together’ Integration Forum Launch

‘Better Together’ Integration Forum Launch

We've launched a how-to forum where you can learn about how Power BI integrates with other Power Platform products.

Top Solution Authors
Top Kudoed Authors