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
arvindyadav
Post Partisan
Post Partisan

Need to use If Condition In Power BI Desktop.

Hi Team,

 

I want to establish If condition in power bi which I have made in excel i.e, =if(Profit > Average Profit/Employee , Profit, Average Profit/Employee).

So how I can make that type of formula in Power BI Desktop. 

I have a measure of Average Profit/Employee.

Please suggest me how to do =if(Profit > Average Profit/Employee, Profit, Average Profit/Employee) in Power BI Desktop.

 

Thanks,

Arvind

19 REPLIES 19
MFelix
Super User
Super User

Hi @arvindyadav,

 

Since this is a measure the value of it changes accordingly to context, so when making the average Profit/Employee you need to change it filter context.

Without additional information it's hard to give you a correct answer but you need to create something like this:

 

Pofict per employee =
IF (
    SUM ( Table[Profit] )
        > CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) );
    SUM ( Table[Profit] );
    CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) )
)

If you can share some sample data and expected result this measure can be made inline with your expectactions, again without any data difficult to respond.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

Wow, it works but the total of Average per employee is displaying same as actual profit total. Why So?

 

Thanks,

Arvind

Hi @arvindyadav,

 

Again without further information on your data is difficult to get the correct answer.

 

It depends on the data model, the columns used on your visuals, etc.

 

Can you share some sample?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

I have no permission to share the sample data also but I can send you a screenshot of the data.Profit per employee.PNG

Please find the image

 

Thanks,

Arvind

Hi @arvindyadav,

 

Again is a question of context, since the measure is based on the total profit value compared with the average you are getting the total profit and not the sum of the above values you need to do a SUMX statment something like this should work:

 

IF (
    HASONEVALUE ( Table[Employee] );
    IF (
        SUM ( Table[Profit] )
            > CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) );
        SUM ( Table[Profit] );
        CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) )
    );
    SUMX (
        Table;
        IF (
            SUM ( Table[Profit] )
                > CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) );
            SUM ( Table[Profit] );
            CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) )
        )
    )
)

Regards,

MFelix

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

Have got any solution regarding my questions?

Everything is fine but the issue is in total profit.

 

Thanks,

Arvind.

HI @arvindyadav,

 

Although you have an image is not clear on the way the tables and the fields in you matrix relate to each other try to do the following.

 

Split the measure in two:

 

Profit/Average =   IF (
        SUM ( Table[Profit] )
            > CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) );
        SUM ( Table[Profit] );
        CALCULATE ( [Average Profit/Employee]; ALL ( Table[Employee] ) )
    )



Total Profit =
IF (
    HASONEVALUE ( Table[Employee] );
    [Profit/Average];
    SUMX ( Table; [Profit/Average] )
)

Then use the last measure on your table.

 

If you cannot do it can you share a sample of you data maybe through private message so I can check the calculations and setup of the model?

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



The above procedure is the same as the previous one so I am still getting the same value as previous.

How to insert an attachment in the thread. I don't see any option to attach the file. Can you explain to me how I can upload the file?

 

 

Send a onedrive, googledrive, dropbox, we transfer link in the post.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

Please find the sample file.

 

 

https://www.dropbox.com/s/liep5krpxcebyvh/Sample.xlsx?dl=0

 

Thanks,

Arvind

Hi @arvindyadav,

 

Create the following two measures:

 

Profict per employee =
IF (
    SUM ( Sheet1[Profit] )
        > CALCULATE ( AVERAGE ( Sheet1[Profit] ); ALL ( Sheet1[AM] ) );
    SUM ( Sheet1[Profit] );
    CALCULATE ( AVERAGE ( Sheet1[Profit] ); ALL ( Sheet1[AM] ) )
)

Total Profit =
IF (
    HASONEFILTER ( Sheet1[AM] );
    [Profict per employee];
    SUMX (
        SUMMARIZE (
            ALL ( Sheet1 );
            Sheet1[Date].[Month];
            Sheet1[AM];
            "ProfitTotal"; [Profict per employee]
        );
        [ProfitTotal]
    )
)

The use the second one to add to your visual should work, see attached PBIX file.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

Now the total issue fixed but the average is not correct. There are 17 AM's and the total profit is 279384.88.

Then The average is 279384.88/17=16434.40. But in your case the average display as 173.85 which is not correct.

 

Please find the attachedprofi by coomunity.PNGaverage.PNG.

 

 

Thanks,

Arvind

Hi @arvindyadav,

 

Replace the first measure by:

 

Profict per employee =
IF (
    SUM ( Sheet1[Profit] ) = BLANK ();
    BLANK ();
    IF (
        SUM ( Sheet1[Profit] )
            > AVERAGEX (
                SUMMARIZE (
                    ALL ( Sheet1 );
                    Sheet1[Date].[Month];
                    Sheet1[AM];
                    "ProfitTotal"; SUM ( Sheet1[Profit] )
                );
                [ProfitTotal]
            );
        SUM ( Sheet1[Profit] );
        AVERAGEX (
            SUMMARIZE (
                ALL ( Sheet1 );
                Sheet1[Date].[Month];
                Sheet1[AM];
                "ProfitTotal"; SUM ( Sheet1[Profit] )
            );
            [ProfitTotal]
        )
    )
)

 

See attach the correct PBIX file.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

Not works. For every month and individual month, the total is the same.

 

Please find attached.not works.PNG

Hi @arvindyadav,

 

Is you tabel setup as the one you gave me on the example file?

 


Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



No

Hi @arvindyadav,

 

As I refer this calculation are based on context so if your model setup is different then the final result will not match what you need.

 

Can you share a mockup of your model so I can make the right adjustment to the formulas?

 

If you want you can share it trhough private message to avoid publishing sensitive data.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @MFelix,

 

Have you got any solution?

 

Thanks,

Arvind

Hi @MFelix,

 

Still not getting the correct value if I adding all value which was I sent in the screenshot that addition is 

$101,966.43

 but here I am getting $81123395.61 which is very huge.

Profit per employee.PNG

Thanks,

Arvind

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.