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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
AgencyPowerBi
Helper III
Helper III

Conditional sum calculation based on filter

Hi, 

 

I have a category filter

 

Category Target

A              All 18-20

B              All 20-25

 

And table in which targets are placed in columns

 

Data1 Data2 All 18-20  All 20-25

A           1        1              5

B            1        2             4

 

So how can I make a measure which calculates the sum of corresponding column (target column) depending on the Selected category?

 

So if pivot is filtered with Category A, I woudl get sum of All 18-20 column, and B Sum of All 20-25 column?

Is it possible?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @AgencyPowerBi,


I'd like to suggest you enter to query editor and unpivot your table columns:

1.gif

 

Then you can use above in pivot table to simply summary specific column range by filter.

 

Sample measures:

Sum index 18~20 = 
CALCULATE (
    SUM ( Table1[Value] ),
    FILTER (
        ALL ( Table1 ),
        Table1[Column Index] >= 18
            && Table1[Column Index] <= 20
            && Table1[Index] = MAX ( Table1[Index] )
    )
)


Sum index 20~25 =
CALCULATE (
    SUM ( Table1[Value] ),
    FILTER (
        ALL ( Table1 ),
        Table1[Column Index] >= 20
            && Table1[Column Index] <= 25
            && Table1[Index] = MAX ( Table1[Index] )
    )
)

4.PNG

 

Regards,

Xiaoxin Sheng

View solution in original post

4 REPLIES 4
afzalphatan
Resolver I
Resolver I

Can you provide pic of base data with intended result..

Well not really. 

 

I wanted to calculate measures in pivot in excel. That way I thought of circumventing visual basic in order to change variables in value pivot field.

 

I have 10 different categories, each has different tagret data for GRP calculation.

So, my idea was calculate GRP data based on category value in filter. 

 

I could do this through if statement in measure, but I have 40 different columns and if statement would be just too long to code.

So I wanted to change if statement with reference table, in which I would pair category with name of the column for the calculation.

 

If that is possible, please let me know how 🙂

Anonymous
Not applicable

HI @AgencyPowerBi,


I'd like to suggest you enter to query editor and unpivot your table columns:

1.gif

 

Then you can use above in pivot table to simply summary specific column range by filter.

 

Sample measures:

Sum index 18~20 = 
CALCULATE (
    SUM ( Table1[Value] ),
    FILTER (
        ALL ( Table1 ),
        Table1[Column Index] >= 18
            && Table1[Column Index] <= 20
            && Table1[Index] = MAX ( Table1[Index] )
    )
)


Sum index 20~25 =
CALCULATE (
    SUM ( Table1[Value] ),
    FILTER (
        ALL ( Table1 ),
        Table1[Column Index] >= 20
            && Table1[Column Index] <= 25
            && Table1[Index] = MAX ( Table1[Index] )
    )
)

4.PNG

 

Regards,

Xiaoxin Sheng

This is great! 

I came to this solution myself. This way I can put a slicer and change category while my values are calculated.

 

Thanks for this solution!

Helpful resources

Announcements
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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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