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
Anonymous
Not applicable

Percentage Contribution to all Levels using measures

Hi Team,

Need help here to calcuate Percentage Contribution to all the levels  .

1.Product to Total Contribution is working fine for me.

ProductPerc =
SUM (PRODUCTS[SALESAMOUNT])
/
CALCULATE (
SUM (PRODUCTS[SALESAMOUNT]),
ALL (Products[ProductName])
)

2.Prod to SubCat Contribution  is not working .

3.Prod to Category Contribution is not working.

Attached the Excel As well which has both data and output(Formula)

https://drive.google.com/open?id=1d2T6ktxhJBn9zwveVfif9ys8zqnTuwRj

My Data:

CategorySubcategoryProductNameSalesAmount
Market1Individaul PersonElectronic7930.75
Market1Individaul PersonFashions9943.13
Market1Individaul PersonMotors2102.55
Market1Legal PersonElectronic11449.65
Market1Legal PersonFashions21364.68
Market1Legal PersonMotors34253.76
Market2Individaul PersonElectronic43611.83
Market2Individaul PersonFashions55028.03
Market2Individaul PersonMotors64145.26
Market2Legal PersonElectronic75891.17
Market2Legal PersonFashions84964.96
Market2Legal PersonMotors95766.34

 

Output:

 

Contru.JPG

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I'll attach the pbix below, but here's the idea:

  • Created dimenson tables for Category, Product and SubCategory and related those to your main table (not really needed in this case, but you would be better off storing keys in your main - aka fact - tables).  You can see how I did that in Query Editior
  • With Product Name from the new dimension product table:
  • Prod to total is the easiest:
Total Sales = sum( Table1[SalesAmount] )

Grand Total Sales Product = CALCULATE( [Total Sales], all( DimProductName[ProductName]))

Product to Total Contribution = DIVIDE( [Total Sales], [Grand Total Sales Product] )
  • But now we get a little more tricky since category and subcategory arent in the table:
  • Grand Total of SubSales = 
    CALCULATE( 
        SUMX( 
            ADDCOLUMNS(
                SUMMARIZE( Table1, DimProductName[ProductName], DimSubcategory[SubCategory]),
                "Total Sub Sales", CALCULATE( [Total Sales], FILTER( ALL( Table1), Table1[Subcategory] = EARLIER( DimSubcategory[SubCategory])
    )
        )
            ), 
            [Total Sub Sales]
        )
    )
    
    Product to SubCat Contribution = 
    DIVIDE(
        [Total Sales],
        [Grand Total of SubSales])
        
    then the same logic for category:
  • Grand Total of Category = 
     
    CALCULATE( 
        SUMX( 
            ADDCOLUMNS(
                SUMMARIZE( Table1, DimProductName[ProductName], DimCategory[Category]),
                "Total Sub Sales", CALCULATE( [Total Sales], FILTER( ALL( Table1), Table1[Category] = EARLIER( DimCategory[Category])
    )
        )
            ), 
            [Total Sub Sales]
        ))
    
    Produc to Categoy Contr = DIVIDE( [Total Sales], [Grand Total of Category])
    Final matrix. Dont need or probably want the grand total on each row, but left them on there for demonstration purposes
  • Final Matrix.png

here's the file:

https://1drv.ms/u/s!Amqd8ArUSwDS1UheqO9YNXskj5R1?e=VniWYv

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

I'll attach the pbix below, but here's the idea:

  • Created dimenson tables for Category, Product and SubCategory and related those to your main table (not really needed in this case, but you would be better off storing keys in your main - aka fact - tables).  You can see how I did that in Query Editior
  • With Product Name from the new dimension product table:
  • Prod to total is the easiest:
Total Sales = sum( Table1[SalesAmount] )

Grand Total Sales Product = CALCULATE( [Total Sales], all( DimProductName[ProductName]))

Product to Total Contribution = DIVIDE( [Total Sales], [Grand Total Sales Product] )
  • But now we get a little more tricky since category and subcategory arent in the table:
  • Grand Total of SubSales = 
    CALCULATE( 
        SUMX( 
            ADDCOLUMNS(
                SUMMARIZE( Table1, DimProductName[ProductName], DimSubcategory[SubCategory]),
                "Total Sub Sales", CALCULATE( [Total Sales], FILTER( ALL( Table1), Table1[Subcategory] = EARLIER( DimSubcategory[SubCategory])
    )
        )
            ), 
            [Total Sub Sales]
        )
    )
    
    Product to SubCat Contribution = 
    DIVIDE(
        [Total Sales],
        [Grand Total of SubSales])
        
    then the same logic for category:
  • Grand Total of Category = 
     
    CALCULATE( 
        SUMX( 
            ADDCOLUMNS(
                SUMMARIZE( Table1, DimProductName[ProductName], DimCategory[Category]),
                "Total Sub Sales", CALCULATE( [Total Sales], FILTER( ALL( Table1), Table1[Category] = EARLIER( DimCategory[Category])
    )
        )
            ), 
            [Total Sub Sales]
        ))
    
    Produc to Categoy Contr = DIVIDE( [Total Sales], [Grand Total of Category])
    Final matrix. Dont need or probably want the grand total on each row, but left them on there for demonstration purposes
  • Final Matrix.png

here's the file:

https://1drv.ms/u/s!Amqd8ArUSwDS1UheqO9YNXskj5R1?e=VniWYv

Hi,

May I request the pbix file again?  The above attached link is expired or not working anymore.

Tks in advance

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.