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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jessiewang
New Member

Percentage Calculation use the sum of one column but the distinct value of another column

Hi there,

Can someone help me creating a calculated column which use the Expected Qty. column's disctict value, but the sum of the Consumed Qty. column filtered by the same production order no. and item no.? See the bottom 4 lines. I would like the result of the 3 lines highlighted in yellow to be combined to a single line as the one at the bottom and the Consumed%=DIVIDE([Consumed Qty]-[Expected], [Expected], 0), but I could not figure out what DAX to use for the Consumed% column so that I can get only 1 line as the one at the bottom.

jessiewang_0-1718235320992.png

 

2 REPLIES 2
Anonymous
Not applicable

Hi @jessiewang 

 

Creating a single row directly from multiple rows is not possible.

 

However, you can implement data presentation by creating visuals.

 

Here's some dummy data

 

“Table”

vnuocmsft_0-1718243711232.png

 

Create columns.

 

column expectedQty = 
CALCULATE(
    MAX('Table'[Expected Qty]),
        FILTER(
            ALL('Table'), 
            'Table'[order no.] = EARLIER('Table'[order no.]) 
            && 
            'Table'[item no.] = EARLIER('Table'[item no.])
        )
    )

 

column consumedTotal = 
CALCULATE(
    SUM('Table'[Consumed Qty]),
        FILTER(
            ALL('Table'),
            'Table'[order no.] = EARLIER('Table'[order no.]) 
            &&
            'Table'[item no.] = EARLIER('Table'[item no.])
        )
    )

 

consumed % = 
DIVIDE(
    'Table'[_consumedTotal] - 'Table'[_expectedQty], 
    'Table'[_expectedQty], 
    0
)

 

I would recommend that you create MEASURES. Compared to COLUMN, MEASURE will take up less memory.

 

measure expectedQty = 
CALCULATE(
    MAX('Table'[Expected Qty]),
        FILTER(
            ALL('Table'), 
            'Table'[order no.] = MAX('Table'[order no.]) 
            && 
            'Table'[item no.] = MAX('Table'[item no.])
        )
    )

 

measure consumedTotal = 
CALCULATE(
    SUM('Table'[Consumed Qty]),
        FILTER(
            ALL('Table'),
            'Table'[order no.] = MAX('Table'[order no.]) 
            &&
            'Table'[item no.] = MAX('Table'[item no.])
        )
    )

 

Measure consumed % = 
 DIVIDE(
    'Table'[measure consumedTotal] - 'Table'[measure expectedQty],
    'Table'[measure expectedQty],
    0
)

Create a visual.

 

vnuocmsft_3-1718243868138.pngvnuocmsft_4-1718243881557.png

 

Here is the result.

vnuocmsft_5-1718244430484.png

 

Regards,

Nono Chen

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

 

Thanks, Nono. I was using measures for Expected Qty and Consumed Qty. But I need to create slicers for Consumed%, so I cannot use measures for it, since measures cannot be used on slicers, only calculated columns can. I was able to combine multiple lines to one line in one of my other Power BI reports but not exactly the same scenario. The % is the most complicated thing in Power BI due to the evaluation context, when use different filters, the result may not be what you want to see. I will continue working on this issue. I'm able to get the result for Consumed% for that line I had in the screenshot. But I still have an issue for the Consumed% for the lines with Item No. TJSP-1LAM.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.