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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply

Comparing values in same colums by year and categorie

Hi

 

I need to create a new calculated column that compares values with the values of a specific categories over several years.

 

So in the example below I wan to compare the % of AAA for one year with the % of all the other codes for the corresponding years. If it is bigger or equal I want to indicate with "1", if its is smaller "0"

 

Knipsel.JPG

 

I'm stuck and don't find a proper solution. Can someone have a look? Thnx!

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

 

View solution in original post

4 REPLIES 4
Ahmedx
Super User
Super User

Screenshot_1.png

Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

 

Thnx!

 

Can you explain the second part of the code, so I get a better understanding?

 
RETURN
IF( MAX('Table'[Code])="AAA",0, IF(__AAA<[% pr],1,0))

  1. You define a variable __AAA, which calculates the percentage ([% pr]) for the category "AAA" in your table. The CALCULATE function applies filters to the data, using ALLEXCEPT to preserve filtering on the 'Table'[Code] and 'Table'[F Year] columns and adding an additional filter where 'Table'[Code] equals "AAA."

  2. Then you have a RETURN statement, which returns a result based on a condition. In this condition, it checks if the maximum code ('Table'[Code]) is equal to "AAA." If it is, it returns 0 (presumably to prevent division by zero). If the code is not "AAA," it goes into the nested condition.

  3. Inside the nested condition, it checks whether the value of __AAA is less than your percentage [% pr]. If __AAA is less than [% pr], it returns 1; otherwise, it returns 0. This is likely used to determine whether the percentage for the "AAA" category exceeds a specified threshold.

Overall, this code appears to be part of a larger data model or data query, and its precise meaning depends on the context and the goals of your analysis.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors