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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
fosterXO
Frequent Visitor

Measure case based on other column text values

Hi,

I have a big model in PowerBI where there are many different aggregation and grouping based on columns being displayed or not on the final table.

 

Simplifying: I need to do a conditional statement doing the sum if the value of column 1 is A1 but doing the MAX() if the value of column 1 is A2.

 

2022-11-12 16_16_37-Book1 - Excel.png

 

I need to have that information in the same colum of the final output. How would you go for this one? 

Thank you very much for your help!

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

@fosterXO 

To obtain correct total you can may try 

Measur =
SUMX (
    VALUES ( 'Table'[Column1] ),
    CALCULATE (
        IF (
            'Table'[Column1] = "A",
            SUM ( 'Table'[Column2] ),
            MAX ( 'Table'[Column2] )
        )
    )
)

View solution in original post

Anonymous
Not applicable

Hi @fosterXO ,

Please have a try.

Create a measure.

Measure =
SWITCH (
    TRUE (),
    MAX ( 'Table'[Column1] ) = "A1",
        SUMX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Column1] = SELECTEDVALUE ( 'Table'[Column1] )
            ),
            'Table'[Column2]
        ),
    MAX ( 'Table'[Column1] ) = "A2",
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Column1] = SELECTEDVALUE ( 'Table'[Column1] )
            ),
            'Table'[Column2]
        ),
    BLANK ()
)

 

vpollymsft_0-1668404937588.png

If I have misunderstood your meaing, please provide more details.

 

Best Regards

Community Support Team _ Polly

 

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

Hi @fosterXO ,

Please have a try.

Create a measure.

Measure =
SWITCH (
    TRUE (),
    MAX ( 'Table'[Column1] ) = "A1",
        SUMX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Column1] = SELECTEDVALUE ( 'Table'[Column1] )
            ),
            'Table'[Column2]
        ),
    MAX ( 'Table'[Column1] ) = "A2",
        MAXX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[Column1] = SELECTEDVALUE ( 'Table'[Column1] )
            ),
            'Table'[Column2]
        ),
    BLANK ()
)

 

vpollymsft_0-1668404937588.png

If I have misunderstood your meaing, please provide more details.

 

Best Regards

Community Support Team _ Polly

 

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

tamerj1
Super User
Super User

@fosterXO 

To obtain correct total you can may try 

Measur =
SUMX (
    VALUES ( 'Table'[Column1] ),
    CALCULATE (
        IF (
            'Table'[Column1] = "A",
            SUM ( 'Table'[Column2] ),
            MAX ( 'Table'[Column2] )
        )
    )
)
AnkitKukreja
Super User
Super User

Hi @fosterXO 

 

I agree with @Anonymous . But the result would be in a separate column. Power BI would not let you show this data in the same column.

 

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
Anonymous
Not applicable

Hi

 

If(selectedvalue(Column1)="A1",sum(column2),Max (Column2))

if you have more choice of column1 values make the if statement each time

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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