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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AnthonyJoseph
Resolver III
Resolver III

Calculate maximum value of a category for a year and its previous year value

Hello Community,

 

I have a table (Table1). I have two slicers "Region" and "Year". I need to create a bar graph which displays the aggregated maximum value of a particular category for the selected year along with the pervious year value of that category based on the "Year" and "Region" selected from slicers.  Below is the table and the expected output.

 

Table1

IdAttributeCategoryYearValueRegion
bf2109761A2020100APAC
b269211c1C202030EMEA
b3ae147b2E202045AMER
8c850f821E202034EUR
e1678c765R202056EUR
517e463b1B202120AMER
ac5bb55b2D202110APAC
454c89784Q202170EMEA
69bf32d85Y202178APAC
6abf32d81A202190APAC
27a48ee42B202118EMEA
f46b64c14C202133AMER
ecef8a755R202144AMER
f90970d47U2022150EMEA
08c3e5ba3R202234APAC
92e24e314A202212EMEA

 

For example: If the year is selected as 2021 then output should be:

 

AnthonyJoseph_0-1651150495146.png

 

Example 2:

if the year 2022 is selected then output should be:

AnthonyJoseph_1-1651150603810.png

 

These charts should be dynamic based on the "Year" and "Region" slicer selection. It would be really great if someone can help me hear.

 

Thanks,

Anthony Joseph

 

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @AnthonyJoseph ,

 

I tried to simulate the issue, but I do not understand how you get 140 for A in the year 2021. The only row I could find that matches that requirement in your data is:

tomfox_0-1651170529512.png

 

Can you explain how get to the 140? 🙂 I might have misunderstood your query...

 

[Edit]

Here one that might come close to what you would like to achieve:

tomfox_1-1651171692871.png

 

Here the code for the measures:

SumValueSelectedYear = 
VAR _selectedYear = MAX ( Table[Year] )
RETURN
CALCULATE (
    SUM ( Table[Value] ),
    Table[Year] = _selectedYear
)
SumValueSelectedYearMinus1 = 
VAR _selectedYear = MAX ( Table[Year] ) - 1
RETURN
CALCULATE (
    SUM ( Table[Value] ),
    REMOVEFILTERS ( Table[Year] ),
    Table2[Year] = _selectedYear
)

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

2 REPLIES 2
tackytechtom
Super User
Super User

Hi @AnthonyJoseph ,

 

I tried to simulate the issue, but I do not understand how you get 140 for A in the year 2021. The only row I could find that matches that requirement in your data is:

tomfox_0-1651170529512.png

 

Can you explain how get to the 140? 🙂 I might have misunderstood your query...

 

[Edit]

Here one that might come close to what you would like to achieve:

tomfox_1-1651171692871.png

 

Here the code for the measures:

SumValueSelectedYear = 
VAR _selectedYear = MAX ( Table[Year] )
RETURN
CALCULATE (
    SUM ( Table[Value] ),
    Table[Year] = _selectedYear
)
SumValueSelectedYearMinus1 = 
VAR _selectedYear = MAX ( Table[Year] ) - 1
RETURN
CALCULATE (
    SUM ( Table[Value] ),
    REMOVEFILTERS ( Table[Year] ),
    Table2[Year] = _selectedYear
)

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Thanks @tackytechtom. You are correct! My bad it should 90 not 140 🙂 Thank you so much for helping me.

 

Also, just wanted to check if there is any way that we can display the values for the category of the selected year instead of prior year. 

 

For example; in the years 2020, 2021, 2022

 

When I select 2022 and 2020, I should see the top 3 values by categories for 2022 and their corresponding values for 2020 (instead of prior year). Similarly when I select 2022, 2020 and 2019. Visual should display the top 3 categories in 2022 and their category value for 2020 and 2019. Please can you help me to achieve this.

 

Really appreciate your help.

 

Thanks,

Anthony Joseph

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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