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
ChrisLoan
Helper I
Helper I

Allocation percentage of margin in different office

Hi everyone

 

I'm dealing with a special situation.

 

We have a Fact table BrutoMargin (Margin) where we have our margin numbers. The margin number has an office key that indicates where the margin is located. But there is one exception, when the margin deals with a number that has to do with an international worker, that's when 75% of the margin number needs to be allocated to the "International Office Key".

 

This is the datamodel situation right now, there are many relationships but the most important one is the relationship with the dimension table "Office":

ChrisLoan_0-1738677139798.png

 

Just to be clear this is a simplified version of what one row in the fact margin table would look like:

 

ChrisLoan_1-1738677622902.png

 

Office key -12 = Office local 1                              International office key -20 = International Office 1

 

The office key is joined with the dimension table "Office". I haven't done anything with "International office key" yet, but the key belongs to the same dimension table "office" to reference it's value.

 

My question is, how do I dynamically allocate 25% of the total margin number (625 euro) to the normal office (office key) ) and 75% (1875 euro) tot the "International office" (international office key), so that I can show this in a matrix table in Power BI.

 

We're using a simple Matrix table in Power BI to visualize the margin with the office and next to it the Margin.

 

The result I would like to see is this in a Matrix table Power BI:

 

ChrisLoan_4-1738678744231.png

 

Thanks!

8 REPLIES 8
Sahir_Maharaj
Super User
Super User

Hello @ChrisLoan,

 

Can you perhaps please try creating a DAX measure for the allocated margin:

Allocated Margin = 
VAR NormalOfficeKey = SELECTEDVALUE('Fact BrutoMarge'[Office_Key])
VAR InternationalOfficeKey = SELECTEDVALUE('Fact BrutoMarge'[International Office Key])
VAR TotalMargin = SUM('Fact BrutoMarge'[Margin])

RETURN 
    SWITCH(
        TRUE(),
        NormalOfficeKey <> BLANK(), TotalMargin * 0.25,
        InternationalOfficeKey <> BLANK(), TotalMargin * 0.75,
        BLANK()
    )

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Sahir,

 

Have you had a chance to look at my reply underneath? It's really urgent.

 

Thanks.

Hi Sahir

 

Let's start again cause I forgot a few things 😁 (the percentage allocation can also go the other way around and is a variable column).

 

I'll give you all the info using a dummy table (one you can replicate in BI) and the result I want.

I've made a dummy table that looks like this:

 

ChrisLoan_0-1738765533807.png

 

Which gives me this result when I simply calculate the total margin (this is without the allocation stuff):

 

ChrisLoan_1-1738765588138.png

 

This is the result with your measure:

 

ChrisLoan_3-1738765776017.png

But this is the result I want (I hardcoded this to get the result):

 

ChrisLoan_4-1738766519388.png

  • (office key -110) ANTN = total of 500 (25% of 2000 = 500)
  • (office key -105) GENT = total of 2000 (100% of 250 + 25% of 3000 + 25% of 4000)
  • (office key -36) IDM = total of 6750 (75% of 2000 + 75% of 3000 + 75% of 4000)

 

 

 

 

How do I do this? 🤔

 

Thank you so much in advance!

 

Hi Sahir

 

Thanks for the quick response! 😊

 

Do I need to connect the "International office key" in a relationship to the Dimension table "Dim Office" before I try this measure?

v-jialongy-msft
Community Support
Community Support

Hi @ChrisLoan 

Please try the following dax:

Adjusted Margin =
SUMX (
    BrutoMargin,
    VAR CurrentOfficeKey = SELECTEDVALUE ( Office[Office Key] )
    VAR IntlOfficeKey = BrutoMargin[International Office Key]
    VAR MarginValue = BrutoMargin[Margin]
    RETURN
        IF (
            NOT ISBLANK ( IntlOfficeKey ),
            SWITCH (
                TRUE (),
                CurrentOfficeKey = BrutoMargin[Office Key], MarginValue * 0.25,
                CurrentOfficeKey = IntlOfficeKey, MarginValue * 0.75,
                0
            ),
            IF ( CurrentOfficeKey = BrutoMargin[Office Key], MarginValue, 0 )
        )
)

 

 

 

If the problem persists, please provide sample data that fully covers your issue (in the form of table or pbix file) and the expected outcome based on the sample data you provided. Please remove any sensitive data in advance.

 

 

 

 

 

Best Regards,

Jayleny

 

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

Hi Jayleny,

 

Have you had a chance to look at my reply underneath? It's really urgent.

 

Thanks.

Hi Jayleny

 

Let's start again cause I forgot a few things! (the percentage allocation can also go the other way around and is a variable column).

 

I'll give you all the info using a dummy table (one you can replicate in BI) and the result I want.

I've made a dummy table that looks like this:

 

ChrisLoan_20-1738767325182.png

 

Which gives me this result when I simply calculate the total margin (this is without the allocation stuff):

 

ChrisLoan_21-1738767367025.png

This is the result with your measure:

 

ChrisLoan_22-1738767403549.png

 

But this is the result I want (I hardcoded this to get the result):

 

ChrisLoan_23-1738767447075.png

 

  • (office key -110) ANTN = total of 500 (25% of 2000 = 500)
  • (office key -105) GENT = total of 2000 (100% of 250 + 25% of 3000 + 25% of 4000)
  • (office key -36) IDM = total of 6750 (75% of 2000 + 75% of 3000 + 75% of 4000)

How do I do this?

 

Thank you so much in advance!

 

Hi Jayleny

 

Thanks, I'm gonna give this a try as soon as possible and I will get back to you if I need more help 😊

 

One question though, do I need to connect the "International office key" in a relationship to the Dimension table "Dim Office" before I try this measure?

 

Thanks.

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.

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors