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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MAbouelatta
New Member

Comparing between two years based on selected branch

Hello Friends

 

I would like to compare between two years (12 months) based on the selected branch from slicer, 

The comparing goes in right way only when not selecting any branch from slicer and it compares the sum of all branches, but after selecting any branch it gives me the below error.

 

I have a table for Calendar and I did the releationship between it and my main table.

and I'm using this measure for last year as follows "

Total LP Act. Spend =
CALCULATE([Total Act. Spend], SAMEPERIODLASTYEAR('Calendar'[Date]))"

 

 

I hope if anyone can solve it

 

MAbouelatta_0-1718799928691.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MAbouelatta ,

 

Here's the simple example data I created:

Date

Value

2023-01-01

100

2023-02-01

100

2023-03-01

100

2023-04-01

100

2023-05-01

100

2023-06-01

100

2024-01-01

50

2024-02-01

50

2024-03-01

50

2024-04-01

50

2024-05-01

50

2024-06-01

50

 

Create a date table and create a join between the two tables:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

 

Create a MEASURE to calculate the sum of the current year:

CurValue = CALCULATE(SUM('Table'[Value]),FILTER('Table',YEAR('Table'[Date])) = YEAR(TODAY())))

 

Create a MEASURE to calculate last year's total:

PreviousValue = CALCULATE(SUM('Table'[Value]), SAMEPERIODLASTYEAR('Date'[Date]))

 

You can calculate whether the number of rows of last year's data selected in your data table is correct by using the following measure:

Last Year Count = 
CALCULATE(
    COUNTROWS('Table'),
    SAMEPERIODLASTYEAR('Table'[Date])
)

 

Using a multi-row card visual object instead of showing two years of data comparison in a table, dragging a MEASURE into a table will report an error.

vhuijieymsft_0-1718847348007.png

 

The final page visual is shown below:

vhuijieymsft_1-1718847348010.png

 

If my program is not successful in helping you solve the problem, I would be grateful if you could provide me with the pbix file or sample data.

 

Remember to remove sensitive data and do not log in to your account in Power BI Desktop when uploading the pbix file.

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @MAbouelatta ,

 

Here's the simple example data I created:

Date

Value

2023-01-01

100

2023-02-01

100

2023-03-01

100

2023-04-01

100

2023-05-01

100

2023-06-01

100

2024-01-01

50

2024-02-01

50

2024-03-01

50

2024-04-01

50

2024-05-01

50

2024-06-01

50

 

Create a date table and create a join between the two tables:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

 

Create a MEASURE to calculate the sum of the current year:

CurValue = CALCULATE(SUM('Table'[Value]),FILTER('Table',YEAR('Table'[Date])) = YEAR(TODAY())))

 

Create a MEASURE to calculate last year's total:

PreviousValue = CALCULATE(SUM('Table'[Value]), SAMEPERIODLASTYEAR('Date'[Date]))

 

You can calculate whether the number of rows of last year's data selected in your data table is correct by using the following measure:

Last Year Count = 
CALCULATE(
    COUNTROWS('Table'),
    SAMEPERIODLASTYEAR('Table'[Date])
)

 

Using a multi-row card visual object instead of showing two years of data comparison in a table, dragging a MEASURE into a table will report an error.

vhuijieymsft_0-1718847348007.png

 

The final page visual is shown below:

vhuijieymsft_1-1718847348010.png

 

If my program is not successful in helping you solve the problem, I would be grateful if you could provide me with the pbix file or sample data.

 

Remember to remove sensitive data and do not log in to your account in Power BI Desktop when uploading the pbix file.

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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