Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dilipan_mp
New Member

Power Query for Multiple category

Dear All,

 

I am having below table in Power BI. I am trying to find the query to do category wise summation and percentage.  Can you help us how to do in Power BI for the required output?

 

In the required output, the following field required

1) Total Production = Produced units KPI Category production wise

2) % of Production = Produced units KPI production-wise/Total Produced units KPI Production-wise

3) % of Power = Total Power consumed where KPI category =Power wise * % of Production

 

Regards

Dilipan

MonthCityKPI categoryKPIKPI valueKPI unit  Required output   
June,2020City APowerPC1500KWH/Month   Total Production% of Total ProductionTotal Production/Total Power
June,2020City APowerPC20KWH/Month City A 500100%500
June,2020City APowerPC30KWH/Month  Product1500100%1
June,2020City BPowerPC1600KWH/Month  Product200%0
June,2020City BPowerPC210KWH/Month  Product300%0
June,2020City BPowerPC320KWH/Month City B 300100%630
June,2020City CPowerPC1200KWH/Month  Product100%0
June,2020City CPowerPC20KWH/Month  Product210033%208
June,2020City CPowerPC380KWH/Month  Product320067%422
June,2020City AProductionProduct1500Units City C 110 280
June,2020City AProductionProduct20Units  Product16055%153
June,2020City AProductionProduct30Units  Product200%0
June,2020City BProductionProduct10Units  Product35045%127
June,2020City BProductionProduct2100Units      
June,2020City BProductionProduct3200Units      
June,2020City CProductionProduct160Units      
June,2020City CProductionProduct20Units      
June,2020City CProductionProduct350Units      
1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @dilipan_mp 

 

Based on your description, I'd like to suggest you try creating measures and displaying the result in a matrix visual. I created data to reproduce your scenario.

Table:

a1.png

 

You may create three measures as below.

Total Production = 
var txt = LEFT(SELECTEDVALUE('Table'[KPI]),2)
return
IF(
    ISINSCOPE('Table'[KPI]),
    IF(
        txt<>"PC",
        SUM('Table'[KPI Value])
    ),
    IF(
        ISINSCOPE('Table'[City]),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                'Table',
                'Table'[KPI Category]="Production"
            )
        ),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                'Table',
                'Table'[KPI Category]="Production"
            )
        )
    )
)
% of Total Production = 
var txt = LEFT(SELECTEDVALUE('Table'[KPI]),2)
return
IF(
    ISINSCOPE('Table'[KPI]),
    IF(
        txt<>"PC",
        DIVIDE(
           SUM('Table'[KPI Value]),
           CALCULATE(
               SUM('Table'[KPI Value]),
               FILTER(
                   ALLEXCEPT('Table','Table'[City]),
                   'Table'[KPI Category]="Production"
               )
           )
        )
    ),
    IF(
        ISINSCOPE('Table'[City]),
        1,
        DISTINCTCOUNT('Table'[City])
    )
)
Total Production/Total Power = 
var txt = LEFT(SELECTEDVALUE('Table'[KPI]),2)
return
IF(
    ISINSCOPE('Table'[KPI]),
    IF(
        txt<>"PC",
        [% of Total Production]*
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                ALLEXCEPT('Table','Table'[City]),
                'Table'[KPI Category]="Power"
            )
        )
    ),
    IF(
        ISINSCOPE('Table'[City]),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                ALLEXCEPT('Table','Table'[City]),
                'Table'[KPI Category]="Power"
            )
        ),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                'Table',
                'Table'[KPI Category]="Power"
            )
        )
    )
)

 

Result:

a2.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @dilipan_mp 

 

Based on your description, I'd like to suggest you try creating measures and displaying the result in a matrix visual. I created data to reproduce your scenario.

Table:

a1.png

 

You may create three measures as below.

Total Production = 
var txt = LEFT(SELECTEDVALUE('Table'[KPI]),2)
return
IF(
    ISINSCOPE('Table'[KPI]),
    IF(
        txt<>"PC",
        SUM('Table'[KPI Value])
    ),
    IF(
        ISINSCOPE('Table'[City]),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                'Table',
                'Table'[KPI Category]="Production"
            )
        ),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                'Table',
                'Table'[KPI Category]="Production"
            )
        )
    )
)
% of Total Production = 
var txt = LEFT(SELECTEDVALUE('Table'[KPI]),2)
return
IF(
    ISINSCOPE('Table'[KPI]),
    IF(
        txt<>"PC",
        DIVIDE(
           SUM('Table'[KPI Value]),
           CALCULATE(
               SUM('Table'[KPI Value]),
               FILTER(
                   ALLEXCEPT('Table','Table'[City]),
                   'Table'[KPI Category]="Production"
               )
           )
        )
    ),
    IF(
        ISINSCOPE('Table'[City]),
        1,
        DISTINCTCOUNT('Table'[City])
    )
)
Total Production/Total Power = 
var txt = LEFT(SELECTEDVALUE('Table'[KPI]),2)
return
IF(
    ISINSCOPE('Table'[KPI]),
    IF(
        txt<>"PC",
        [% of Total Production]*
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                ALLEXCEPT('Table','Table'[City]),
                'Table'[KPI Category]="Power"
            )
        )
    ),
    IF(
        ISINSCOPE('Table'[City]),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                ALLEXCEPT('Table','Table'[City]),
                'Table'[KPI Category]="Power"
            )
        ),
        CALCULATE(
            SUM('Table'[KPI Value]),
            FILTER(
                'Table',
                'Table'[KPI Category]="Power"
            )
        )
    )
)

 

Result:

a2.png

 

Best Regards

Allan

 

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 for taking time and helping to create the query and Power BI file also.

 

God Bless you.

dilipan_mp
New Member

Hi,

 

Thanks for your reply.

 

Column city is common for Production and Power

Fowmy
Super User
Super User

@dilipan_mp 

What is the common key or a column that defines the link between Production and Power, for example, Product 1 and PC1, you cannot hard code, you need to have some relationship then you can merge and group and do the calculation easy to get the results.

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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