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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Kat2014
New Member

Weekly comparison YOY

Hello all,

I’m new to Power BI and was wondering if someone could help me with this. I watched some videos on it and read a few things online, but it didn’t quite match what I’d like to achieve.  I’m not familiar with all the Power BI terms just yet so be nice haha.

I’ve got two spreadsheets containing the following information.

First spreadsheet

  • Booking date
  • Brand
  • Revenue
  • People travelling
  • Travel date
  • Salesperson

Second spreadsheet

  • Booking date
  • Revenue targets for each day for this FY and next FY that are based on different brands. Our FY runs from September to August, not sure if that’s relevant

 

I’d like to create a table and visual that will show the revenue per week per brand for the last 4 weeks (Mon-Sun) and the same dates last year and compare them to this year’s target.

For example, booking week 22.7.24 – 28.7.24 compared to 22.7.23 – 28.7.23, even though last year it wasn’t Mon-Sun. It should always show the last 4 weeks (Mon-Sun) when updating the data. I’m struggling with it as we don’t compare week numbers.

The X axis should show 4 bars reflecting the last 4 weeks Mon-Sun (8.7 - 14.7.24; 15.7. – 21.7.24; 22.7. – 28.7.24 and 29.7. 4.8.24, for example), a bar next to it with the same dates but for 2023 and a bar with the targets for this year. The Y axis should show the revenue.

Is that possible?

Any help is appreciated. If you can point me in the right direction that would be amazing. Thank you very much for your help in advance. I hope the above makes sense.

 

Thank you 😊

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @Kat2014 

 

Here I create a set of sample:

Revenue Table:

vzhengdxumsft_0-1723180353319.png

Target Table:

vzhengdxumsft_1-1723180359681.png

Then add a calculated table:

Table 2 = {1,2,3,4}

vzhengdxumsft_3-1723180445384.png

add a calculated column in table 2:

weeks =
VAR _currentValue = 'Table 2'[Value]
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
RETURN
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    ) & "--"
        & MAXX (
            FILTER (
                _vtable,
                YEAR ( [Date] ) = YEAR ( TODAY () )
                    && [_WeekNum] = _NowNumber - _currentValue
            ),
            [Date]
        )

vzhengdxumsft_4-1723180483949.png

At last, add 3 measure:

2024_revenue =
VAR _currentValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
VAR _mindate =
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
RETURN
    CALCULATE (
        SUM ( Revenue[Revenue] ),
        FILTER (
            ALLSELECTED ( Revenue ),
            'Revenue'[Booking date] >= _mindate
                && 'Revenue'[Booking date] <= _maxdate
        )
    )
2023_revenue =
VAR _currentValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
VAR _mindate =
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
RETURN
    CALCULATE (
        SUM ( Revenue[Revenue] ),
        FILTER (
            ALLSELECTED ( Revenue ),
            'Revenue'[Booking date]
                >= DATE ( YEAR ( _mindate ) - 1, MONTH ( _mindate ), DAY ( _mindate ) )
                && 'Revenue'[Booking date]
                    <= DATE ( YEAR ( _maxdate ) - 1, MONTH ( _maxdate ), DAY ( _maxdate ) )
        )
    )
2024_target =
VAR _currentValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
VAR _mindate =
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
RETURN
    CALCULATE (
        SUM ( Target[Revenue target] ),
        FILTER (
            ALLSELECTED ( 'Target' ),
            'Target'[Booking date] >= _mindate
                && 'Target'[Booking date] <= _maxdate
        )
    )

The result is as follow:

vzhengdxumsft_5-1723180579107.png

 

 

Best Regards

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

View solution in original post

1 REPLY 1
v-zhengdxu-msft
Community Support
Community Support

Hi @Kat2014 

 

Here I create a set of sample:

Revenue Table:

vzhengdxumsft_0-1723180353319.png

Target Table:

vzhengdxumsft_1-1723180359681.png

Then add a calculated table:

Table 2 = {1,2,3,4}

vzhengdxumsft_3-1723180445384.png

add a calculated column in table 2:

weeks =
VAR _currentValue = 'Table 2'[Value]
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
RETURN
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    ) & "--"
        & MAXX (
            FILTER (
                _vtable,
                YEAR ( [Date] ) = YEAR ( TODAY () )
                    && [_WeekNum] = _NowNumber - _currentValue
            ),
            [Date]
        )

vzhengdxumsft_4-1723180483949.png

At last, add 3 measure:

2024_revenue =
VAR _currentValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
VAR _mindate =
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
RETURN
    CALCULATE (
        SUM ( Revenue[Revenue] ),
        FILTER (
            ALLSELECTED ( Revenue ),
            'Revenue'[Booking date] >= _mindate
                && 'Revenue'[Booking date] <= _maxdate
        )
    )
2023_revenue =
VAR _currentValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
VAR _mindate =
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
RETURN
    CALCULATE (
        SUM ( Revenue[Revenue] ),
        FILTER (
            ALLSELECTED ( Revenue ),
            'Revenue'[Booking date]
                >= DATE ( YEAR ( _mindate ) - 1, MONTH ( _mindate ), DAY ( _mindate ) )
                && 'Revenue'[Booking date]
                    <= DATE ( YEAR ( _maxdate ) - 1, MONTH ( _maxdate ), DAY ( _maxdate ) )
        )
    )
2024_target =
VAR _currentValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _vtable =
    ADDCOLUMNS (
        CALENDAR ( MIN ( 'Revenue'[Booking date] ), MAX ( 'Revenue'[Booking date] ) ),
        "_Weekday", WEEKDAY ( [Date], 2 ),
        "_WeekNum", WEEKNUM ( [Date], 2 )
    )
VAR _NowNumber =
    MAXX ( FILTER ( _vtable, [Date] = TODAY () ), [_WeekNum] )
VAR _mindate =
    MINX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
VAR _maxdate =
    MAXX (
        FILTER (
            _vtable,
            YEAR ( [Date] ) = YEAR ( TODAY () )
                && [_WeekNum] = _NowNumber - _currentValue
        ),
        [Date]
    )
RETURN
    CALCULATE (
        SUM ( Target[Revenue target] ),
        FILTER (
            ALLSELECTED ( 'Target' ),
            'Target'[Booking date] >= _mindate
                && 'Target'[Booking date] <= _maxdate
        )
    )

The result is as follow:

vzhengdxumsft_5-1723180579107.png

 

 

Best Regards

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.