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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Grahamwest
Regular Visitor

Need help with formula

Hello Folks,

 

I got an example table with:

 

 

Batch                           Qty (Kg)          Auction no.

A1025                           5                                1

A1025                           5                                2

A1026                           4                                2

A1025                           5                                3

A1027                           7                                3

A1025                           5                                4

A1027                           7                                4

 

Now I want a new calculated table with:

 

If I select Any of the auction let say 2 so result should be:

 

Batch                           Qty (Kg)         

A1025                           5                               

A1026                           4                               

 

But if I select multiple auctions let say 1,2 & 3 so result should be: 

 

Batch                           Qty (Kg)         

A1025                           5                               

A1026                           4                               

A1027                           7                               

 

Which means I should not sum up instead gives me the unique value of each auction.

 

How to achieve this?

 

Best regards,

 

Graham

10 REPLIES 10
Anonymous
Not applicable

Hi @Grahamwest,

 

Nope, power bi not support create calculated column/table based on slicer.

Calculated Column/Table Change Dynamically According to Slicer Selection in the Report.

 

Regards,

XIaoxin Sheng

Can it be done by using measure?

 

I have almost reached at the end, but now the porblem is totals. See this:

 

I tried doing it mathematically:

 

-TotalOfferedforunique = DIVIDE(SUM('Live Auction'[Offered QTY]),COUNT('Live Auction'[Batch No]))

-Distict Batch Count = DISTINCTCOUNT('Live Auction'[Batch No])

-Unique Offered QTY (MT) = [TotalOfferedforunique]*[Distict Batch Count]

 

Now the same formula is getting applied on its total, which I dont want. I want the sum of the columns.

 

When I am exporting it in excel and adding up it is giving me the unique value but not when I am seeing it in BI.

 

Thanks,

Graham

Anonymous
Not applicable

Hi @Grahamwest,

 

Actually, you only need to switch the summary mode, then it will to show the distinct value.

5.PNG

 

Notice: Summary mode 'Minimum', 'Maximum', 'Median', 'Average' suitable for your requirement.

 

Measure version:

Qty(Kg) = CALCULATE(LASTNONBLANK('sample'[ Qty (Kg)],[ Qty (Kg)]),ALLSELECTED('sample'[Auction no.]))

 

 

Regards,

Xiaoxin Sheng

Hi @Anonymous

 

Thanks for the reply!!!

 

I need the sum of the totals: (5+4+7) = 16

 

Please help!!!

 

Thanks,

Graham

Anonymous
Not applicable

HI @Grahamwest,

 

You can use below measure to achieve your requirement, I modified formula to display total qty at 'Total'.

Qty(Kg) =
IF (
    ISFILTERED ( 'sample'[Batch] ),
    CALCULATE (
        LASTNONBLANK ( 'sample'[ Qty (Kg)], [ Qty (Kg)] ),
        ALLSELECTED ( 'sample'[Auction no.] )
    ),
    SUMX (
        SUMMARIZE (
            ALLSELECTED ( 'sample' ),
            'sample'[Batch],
            "QTY", DISTINCT ( 'sample'[ Qty (Kg)] )
        ),
        [QTY]
    )
)

9.PNG

 

Regards,

Xiaoxin Sheng

Hi, @Anonymous

 

You are awesome!!! This is what I wanted. Thanks a lot for your help.

 

Just a slight problem, when I am selecting 2 auctions which have unique value/no duplicate value it is giving me below error:

 

image.png

 

please help me on this too.

 

Also I would like to understand the formula what it means.

 

Thanks again!!!

 

 

Thanks,

Graham

Also,

 

when i am selecting all of the auctions it is giving me the same value:

 

image.png

It is working fine if i am not taking any attribute in a column.

 

Thanks,

Graham

Anonymous
Not applicable

Hi @Grahamwest,

 

Based on test, this formula works when I test to choose multiple unique records in slicer.

 

11.PNG

 

10.PNG

 

Have you modified the group column or slicer column? If not, please share the sample pbix file to test.

 

BTW, I also update the formula condition to confirm it can correct filter the total row, maybe you can try it.

Qty(Kg) = 
IF (
    COUNTROWS ( 'sample' ) <> COUNTROWS ( ALLSELECTED ( 'sample' ) ),
    CALCULATE (
        LASTNONBLANK ( 'sample'[ Qty (Kg)], [ Qty (Kg)] ),
        ALLSELECTED ( 'sample'[Auction no.] )
    ),
    SUMX (
        SUMMARIZE (
            ALLSELECTED ( 'sample' ),
            'sample'[Batch],
            "QTY", DISTINCT ( 'sample'[ Qty (Kg)] )
        ),
        [QTY]
    )
)

 

 

Regards,

XIaoxin Sheng

Hi @Anonymous

 

I have tried this one too, but it is giving me same result,

 

Can I have you email Id so that I can send you the data and that may be esier for you to work upon?

 

Thanks,

Graham

Anonymous
Not applicable

Hi @Grahamwest,


You can share the sample link with private message, I will check and test on it.

 

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.