Forum Discussion
Comparing between two years based on selected branch
- Anonymous2 years ago
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.
The final page visual is shown below:
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 TeamIf 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!
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.
The final page visual is shown below:
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!