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
PBINovice123
Frequent Visitor

Need help with conditional formula with a combo of max and sum

Hi,

 

I have a formula that I'm trying to figure out but so far have been unsuccessful.  

 

I'm trying to calculate the total budget across all departments, using the following logic: 

 

Sum of all Total Budgets Per Dept ID where Total Budget Per Dept ID = Max of Shared Budget + Separate Budget

 

For example, the total budget for Dept ID 54321 is 300,000 (the max of the shared budgets of 200,000 plus the separate budget of 100,000).  

 

Dept ID StructureBudgetEmployee
12345Separate       100,000Kim 
12345Separate       100,000John
54321Shared       100,000Chris
54321Shared       200,000Ashley
54321Separate       100,000Kelly

 

Any help would be appreciated!  Thanks so much.  

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @PBINovice123 

 

Please try the following methods.

Total budget =
CALCULATE (
    MAX ( 'Table'[Budget] ),
    FILTER (
        'Table',
        [Dept ID] = EARLIER ( 'Table'[Dept ID] )
            && [Structure] = "Shared"
    )
)
    + CALCULATE (
        SUM ( 'Table'[Budget] ),
        FILTER (
            'Table',
            [Dept ID] = EARLIER ( 'Table'[Dept ID] )
                && [Structure] = "Separate"
        )
    )

vzhangti_0-1656482290218.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @PBINovice123 

 

Please try the following methods.

Total budget =
CALCULATE (
    MAX ( 'Table'[Budget] ),
    FILTER (
        'Table',
        [Dept ID] = EARLIER ( 'Table'[Dept ID] )
            && [Structure] = "Shared"
    )
)
    + CALCULATE (
        SUM ( 'Table'[Budget] ),
        FILTER (
            'Table',
            [Dept ID] = EARLIER ( 'Table'[Dept ID] )
                && [Structure] = "Separate"
        )
    )

vzhangti_0-1656482290218.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

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

ribisht17
Super User
Super User

@PBINovice123 

 

You can replace Null easily with 

ribisht17_0-1656294567931.png

 

For the first one I am not facing such issues, maybe you have more number of columns there, I need to see the exact sample data-set

 

ribisht17_0-1656295011294.png

Also please check again if you are giving the filter below

Max Shared Budget per ID = CALCULATE(max(Sheet2[Budget]),ALLEXCEPT(Sheet2,Sheet2[Dept ID ],Sheet2[Structure]),Sheet2[Structure]="Shared")

 

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

PBINovice123
Frequent Visitor

Thanks a lot, but unfortunately it still isn't computing as intended. 

 

One thing I noticed is that the "Shared Budget per ID" formula is giving me a value even if none of the structures within the field are "Shared". 

 

Additionally, I failed to mention that some of the values in the "Structure" column are blank and should be treated like a Separate structure.  Do you know how I would account for all of this? 

 

Thanks again!

ribisht17
Super User
Super User

@PBINovice123 

 

Step 1

Max Shared Budget per ID = CALCULATE(max(Sheet2[Budget]),ALLEXCEPT(Sheet2,Sheet2[Dept ID ],Sheet2[Structure]),Sheet2[Structure]="Shared")
 
 
Step 2
Separate Budget per ID = CALCULATE(max(Sheet2[Budget]),ALLEXCEPT(Sheet2,Sheet2[Dept ID ]),Sheet2[Structure]="Separate")
 
Solution=[Max Shared Budget per ID]Sheet2[Separate Budget per ID]
ribisht17_0-1656268677102.png

Here is my video on ALL,ALLEXCEPT function https://youtu.be/fEIaJigVfFg if you wish to see

 

Regards,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

 

 
 
 

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.