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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
shiibaa
Regular Visitor

Creating a measure with SUMX and IF/OR Statements

Hi everyone,

 

I am pretty new to Power BI and struggling a bit. Apologies if this was asked a bunch of times, but I would appreciate any and all help!

 

I am trying to create a new measure for a table using multiple parameters. However, depending on a column value, I can use one OR multiple parameters. I'm having trouble writing out that formula. 

 

 

So I have: 

Total_Amount = SUMX(Table, IF(Table[ColumnA] = "abc", Table[ColumnB])) * 'Parameter'[Parameter Value]  - works fine! 

 

However, If ColumnA = "efg", then I want SUMX(Table, IF(Table[ColumnA] = "abc", Table[ColumnB])) * 'Parameter'[Parameter Value]  * 'Parameter2'[ParameterValue]  - also works fine by itself 

 

The two work fine standalone, however, when I try to combine them I am getting an error.

I tried doing: IF(ColumnA = "abc", SUMX(Table,'Table'[ColumnB]) * 'Parameter'[ParameterValue], IF(ColumnA = "efg", SUMX(Table, 'Table'[ColumnB])  * 'Parameter'[Parameter Value]  * 'Parameter2'[ParameterValue])) which gives me the error: "a single value for column in table cannot be determined"

 

Does anyone know what's the correct to write this out?

Thank you in advanced!!! 

 

4 REPLIES 4
Anonymous
Not applicable

Hi @shiibaa

 

I dont see any issues with the formula.

 

I hope you are trying this with calculated column. You can try SWITCH as well, but switch is also internally converted as IF function only.

 

Ex:

SWITCH(Cnt_Max[Score],"Good",Cnt_Max[Ticket_id]+100000,"Bad",DIVIDE(Cnt_Max[Ticket_id],Cnt_Max[Ticket_id]))

 

Thanks

Raj

Hi @Anonymous, 

 

thanks for your comment.
I am trying this with a measure because I am using a what if parameter... When I try to use SWITCH, I get the  "a single value for column in table cannot be determined" error.

 

 

Anonymous
Not applicable

Post some sample data ( copy - pastable format) with expected result.

 

Thanks

Raj

Sample data:

Line ItemUnit Price
A$0.50
B$2
C$10

 


I have two What If Parameters 

Parameter 1, Parameter 2.

For Line Item A, the Total Price = Unit Price * Parameter 1.
For Line Item B, the Total Price = Unit Price * Parameter 1 * Parameter 2.

I currently have: Measure = SUMX(Table, IF(Table[Line Item] = "A", Unit Price) * Parameter 1. I am getting an error when I try to to IF([Line Item] = "A", SUMX(Table, [Unit Price]) * Parameter 1, If([Line Item] = "B", SUMX(Table, [Unit Price]) * Parameter 1 * Parameter 2)).

 

I hope that provides some context. Thanks! 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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