Forum Discussion

MAbouelatta's avatar
MAbouelatta
Regular Visitor
2 years ago
Solved

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

 

 

  • Anonymous's avatar
    Anonymous
    2 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 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!

1 Reply

  • Anonymous's avatar
    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.

     

    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!