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
sakolwakar
New Member

Maximum Value with IF Condition

I'm trying to calculate the maximum value with multiple conditions in Power BI.

 

The dataframe is:

Year    Company         Bond            Branch      Group     Type    Value
2016    BANCO DO BRASIL INDEPENDENTE    RISK        RETAIL    NOMINAL 4061567
2016    BANCO DO BRASIL INDEPENDENTE    ACUMULAÇÃO  RETAIL    NOMINAL 1901920
2017    BANCO DO BRASIL INDEPENDENTE    RISK        CORPORATE REAL    439499
2017    BANCO DO BRASIL INDEPENDENTE    RISK        RETAIL    REAL    356231
2016    BRADESCO        INDEPENDENTE    RISK        CORPORATE NOMINAL 347369
2016    BANCO DO BRASIL INDEPENDENTE    ACUMULAÇÃO  RETAIL    REAL    310920
2016    BANCO DO BRASIL LIGADO A BANCO  RISK        CORPORATE NOMINAL 12091
2016    BANCO DO BRASIL INDEPENDENTE    ACUMULAÇÃO  RETAIL    REAL    1021
2017    BANCO DO BRASIL INDEPENDENTE    RISK        CORPORATE REAL    446

I want to create a column with the maximum value by year, Bond, Branch, Group and Type disconsidering Company

I've already tried the following code:

 

MAX = CALCULATE(MAX(data[Value]);
      FILTER(ALLEXCEPT(data;data[Company];
      data[Year] = data[Year] 
      && data[Branch] = data_segmento_anual[Branch]
      && data_segmento_anual[Group] = data_segmento_anual[Group]
      && data_segmento_anual[Bond] = data_segmento_anual[Bond]
      && data_segmento_anual[Type] = data_segmento_anual[Type]))

I'm expecting this result:

 

Year    Company             Bond            Branch      Group     Type    Value   MAX 
    2016    BANCO DO BRASIL INDEPENDENTE    RISK        RETAIL    NOMINAL 4061567 4061567
    2016    BANCO DO BRASIL INDEPENDENTE    ACUMULAÇÃO  RETAIL    NOMINAL 1901920 1901920 
    2017    BANCO DO BRASIL INDEPENDENTE    RISK        CORPORATE REAL    439499  439499
    2017    BANCO DO BRASIL INDEPENDENTE    RISK        RETAIL    REAL    356231  356231
    2016    BRADESCO        INDEPENDENTE    RISK        CORPORATE NOMINAL 347369  347369
    2016    BANCO DO BRASIL INDEPENDENTE    ACUMULAÇÃO  RETAIL    REAL    310920  310920
    2016    BANCO DO BRASIL LIGADO A BANCO  RISK        CORPORATE NOMINAL 12091   12091
    2016    BANCO DO BRASIL INDEPENDENTE    ACUMULAÇÃO  RETAIL    REAL    1021    310920
    2017    BANCO DO BRASIL INDEPENDENTE    RISK        CORPORATE REAL    446     439499
1 ACCEPTED SOLUTION
Kalpavruksh
Resolver I
Resolver I

Hi,
Your ALLEXCEPT is removing all context except for Company, which is the opposite of what you want. Put what you want to keep inside ALLEXCEPT.
CALCULATE (
    MAX ( data[Value] );
    ALLEXCEPT (
        data;
        data[year];
        data[Branch];
        data_segmento_anual[Bond];
        data_segmento_anual[Group];
        data_segmento_anual[Type]
    )
)

 

The other way to do it is to use ALL to specify the column that you want to be ignored.
CALCULATE ( MAX ( data[Value] ); ALL ( data[Company] ) )

Kalpavruksh Technologies | Microsoft Gold Partner
Denmark | USA | India | Germany

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Kalpavruksh
Resolver I
Resolver I

Hi,
Your ALLEXCEPT is removing all context except for Company, which is the opposite of what you want. Put what you want to keep inside ALLEXCEPT.
CALCULATE (
    MAX ( data[Value] );
    ALLEXCEPT (
        data;
        data[year];
        data[Branch];
        data_segmento_anual[Bond];
        data_segmento_anual[Group];
        data_segmento_anual[Type]
    )
)

 

The other way to do it is to use ALL to specify the column that you want to be ignored.
CALCULATE ( MAX ( data[Value] ); ALL ( data[Company] ) )

Kalpavruksh Technologies | Microsoft Gold Partner
Denmark | USA | India | Germany

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much @Kalpavruksh for assisting me in this solution. I was stuck at this and needed inputs immediately and didn't know and was not much sure if I will get any input on the same. The questions seems to be pretty complex and you solved it easily.

 

Again thanks much!

Thanks for the input @Kalpavruksh  Let me see how this works 🙂

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.

Top Solution Authors