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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.