Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
LiamReidy
Helper I
Helper I

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

Current View using Table 1Current 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

Current View using Table 2Current 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
v-shex-msft
Community Support
Community Support

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
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
LiamReidy
Helper I
Helper I

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

v-shex-msft
Community Support
Community Support

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
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@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.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors