Reply
TJHughes
Frequent Visitor

How to get a the sum income total for last week in previous year

I need to be able to get the sum of the "This Week Income" column per branch for the last week, or max week, for the previous year selected in the current report. We then use this to compare for YTD differences etc.

 

The table I am using has data set up as follows:

YEARWEEKTHIS_WEEK_BRANCHTHIS WEEK INCOME
202325S1125
202325S1110
202326S5645
202326S5615
202327S9885
202327S9825
202328S4295
202328S4245
202329S1130
202329S1185
202330S525
202330S5295
202331S7780
202331S7730
202332S1190
202332S115
202333S56100
202333S5680
202334S9850
202334S9890
202335S4260
202335S42100
202336S1170
202336S1150
202337S5290
202337S5260
202338S7710
202338S7770
202339S1115
202339S1190
202340S5625
202340S5610
202341S9845
202341S9815
202342S4285
202342S4225
202343S1195
202343S1145
202344S5230
202344S5285
202345S775
202345S7795
202346S1180
202346S1130
202347S5690
202347S565
202348S98100
202348S9880
202349S4250
202349S4290
202350S1160
202350S11100
202351S5270
202351S5250
202352S7790
202352S7760
202352S115
202352S5680
202352S9890
202352S42100
202352S1150
202352S5260
202352S7770
202352S1190
202352S5610
202352S9815
202352S4225
202352S1145
202352S5285
202352S7795
202352S1130
202352S565
202352S9880
202352S4290
202352S11100
202352S5250
202352S7760
202352S115
202352S5680
202352S9890
202352S42100
202352S1150
202352S5260
202352S7770
202352S1190
202352S5610
202352S9815
202352S4225
202352S1145
202352S5285
202352S7795
202352S1130
202352S565
202352S9880
202352S4290
202352S11100
202352S5250
202352S7760
202425S1180
202425S1130
202425S1185
202426S5690
202426S565
202426S5695
202427S98100
202427S9880
202427S9830
202428S4250
202428S4290
202428S425
202429S1160
202429S11100
202429S1180
202430S5270
202430S5250
202430S5290
202431S7790
202431S7760
202431S77100
202432S1110
202432S1170
202432S1150
202433S5615
202433S5690
202433S5660
202434S9825
202434S9810
202434S9870
202435S4245
202435S4215
202435S4290
202436S1185
202436S1125
202436S1110
202437S5295
202437S5245
202437S5215
202438S7730
202438S7785
202438S7725
202439S115
202439S1195
202439S1145
202440S5680
202440S5630
202440S5685
202441S9890
202441S985
202441S9895
202442S42100
202442S4280
202442S4230
202443S1150
202443S1190
202443S115
202444S5260
202444S52100
202444S5280
202445S7770
202445S7750
202445S7790
202446S1190
202446S1160
202446S11100
202447S5610
202447S5670
202447S5650
202448S9815
202448S9890
202448S9860
202449S4225
202449S4210
202449S4270
202450S1145
202450S1115
202450S1190
202451S5285
202451S5225
202451S5210
202452S7795
202452S7745
202452S7715

 

I tried creating a sumarize table using the following but it is not giving me the correct results:

EOPY = SUMMARIZE(FIGURES,
FIGURES[YEAR],
FIGURES[WEEK NO],
FIGURES[THIS_WEEK_BRANCH],
"INCOME",SUM(FIGURES[THIS WEEK INCOME]))
1 ACCEPTED SOLUTION
TJHughes
Frequent Visitor

Fixed it, needed to add the branch to the filter in my code. So it makes it:

Latest Year =
VAR _LatestYear =
            CALCULATETABLE(SUMMARIZE(OR_RORDERINCOMES1,OR_RORDERINCOMES1[YEAR]))

VAR _MaxWeek =
    MAXX(
        FILTER(
            CALCULATETABLE(
                SUMMARIZE(OR_RORDERINCOMES1, OR_RORDERINCOMES1[YEAR],OR_RORDERINCOMES1[WEEK No]) ,
                REMOVEFILTERS()  ),
        OR_RORDERINCOMES1[YEAR] = _LatestYear-1),
    OR_RORDERINCOMES1[WEEK No]  )

VAR _EOYIncome =
    CALCULATE(
        [This Week Income (Nett)], //This week income is just a measure that is SUM(THIS_WEEK_INCOME)/1.2 to remove VAT.
        FILTER( ALL( OR_RORDERINCOMES1),
        OR_RORDERINCOMES1 [YEAR] = _LatestYear -1
            && OR_RORDERINCOMES1 [WEEK NO] = _MaxWeek  ), VALUES(OR_RORDERINCOMES1[THIS_WEEK_INCOME_BRANCH] )  )


RETURN

_EOYIncome

View solution in original post

4 REPLIES 4
TJHughes
Frequent Visitor

Fixed it, needed to add the branch to the filter in my code. So it makes it:

Latest Year =
VAR _LatestYear =
            CALCULATETABLE(SUMMARIZE(OR_RORDERINCOMES1,OR_RORDERINCOMES1[YEAR]))

VAR _MaxWeek =
    MAXX(
        FILTER(
            CALCULATETABLE(
                SUMMARIZE(OR_RORDERINCOMES1, OR_RORDERINCOMES1[YEAR],OR_RORDERINCOMES1[WEEK No]) ,
                REMOVEFILTERS()  ),
        OR_RORDERINCOMES1[YEAR] = _LatestYear-1),
    OR_RORDERINCOMES1[WEEK No]  )

VAR _EOYIncome =
    CALCULATE(
        [This Week Income (Nett)], //This week income is just a measure that is SUM(THIS_WEEK_INCOME)/1.2 to remove VAT.
        FILTER( ALL( OR_RORDERINCOMES1),
        OR_RORDERINCOMES1 [YEAR] = _LatestYear -1
            && OR_RORDERINCOMES1 [WEEK NO] = _MaxWeek  ), VALUES(OR_RORDERINCOMES1[THIS_WEEK_INCOME_BRANCH] )  )


RETURN

_EOYIncome
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1742027214549.png

 

 

Jihwan_Kim_0-1742027078158.png

 

income: = 
SUM( FIGURES[INCOME] )

 

Latest year YTD income vs previous year YTD: =
VAR _latestyear =
    MAXX (
        CALCULATETABLE ( SUMMARIZE ( FIGURES, PERIOD[YEAR] ), REMOVEFILTERS () ),
        PERIOD[YEAR]
    )
VAR _latestweek =
    MAXX (
        FILTER (
            CALCULATETABLE (
                SUMMARIZE ( FIGURES, PERIOD[YEAR], PERIOD[WEEK] ),
                REMOVEFILTERS ()
            ),
            PERIOD[YEAR] = _latestyear
        ),
        PERIOD[WEEK]
    )
VAR _latestyearytd =
    CALCULATE (
        [income:],
        FILTER (
            ALL ( PERIOD ),
            PERIOD[YEAR] = _latestyear
                && PERIOD[WEEK] <= _latestweek
        )
    )
VAR _sameperiodpreviousyear =
    CALCULATE (
        [income:],
        FILTER (
            ALL ( PERIOD ),
            PERIOD[YEAR] = _latestyear - 1
                && PERIOD[WEEK] <= _latestweek
        )
    )
RETURN
    DIVIDE ( _latestyearytd - _sameperiodpreviousyear, _sameperiodpreviousyear )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thanks for reply,

 

I dont think I have been clear so I have created an example report with some data in. The data I have is a table which has the WEEK (which is YYYY/WW), which we use in report to income for that week. I then have YEAR and WEEK no, which are the WEEK split. The BATCH_DATE is the date that data was collected. The BRANCH is for the branch number it applies too.

 

What I need to do is see what the weeks income for a branch is for the last week of the previous year selected. So if they select WEEK 2024/50 then the result is for the last week in the data for YEAR 2023, in this case for YEAR 2023 and WEEK No 52 or WEEK 2023/52. We can then use this to get comparisons for each branch on what the income is for the selected week against what it was for the last week in the year before.

 

I cannot add  a copy of the PBIX file but here is a screen shot of the report visual showing week slicer and table showing list of branches and the week selected income total but I need it to then show the weeks total for the last week of the previous year, that is what I cannot get.

TJHughes_0-1742745803083.png

Here is a screenshot of the data table:

TJHughes_1-1742745839962.png

 

I hope that makes sense and is clearer.

I have done the following and it calculates the total of the last week of previous year selected but shows the grand total for each row, it is not filtering it by branch?

 

Measure I have used is:

 

Latest Year =
VAR _LatestYear =
            CALCULATETABLE(SUMMARIZE(OR_RORDERINCOMES1,OR_RORDERINCOMES1[YEAR]))

VAR _MaxWeek =
    MAXX(
        FILTER(
            CALCULATETABLE(
                SUMMARIZE(OR_RORDERINCOMES1, OR_RORDERINCOMES1[YEAR],OR_RORDERINCOMES1[WEEK No]) ,
                REMOVEFILTERS()  ),
        OR_RORDERINCOMES1[YEAR] = _LatestYear-1),
    OR_RORDERINCOMES1[WEEK No]  )

VAR _EOYIncome =
    CALCULATE(
        [This Week Income (Nett)],
        FILTER( ALL( OR_RORDERINCOMES1),
        OR_RORDERINCOMES1 [YEAR] = _LatestYear -1
            && OR_RORDERINCOMES1 [WEEK NO] = _MaxWeek  )  )


RETURN

_EOYIncome
 
Just need this to break it down for each branch location as it looks like this currently:
TJHughes_0-1742774441571.png

 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)