Forum Discussion
1 or 0 based on sum two columns
Hi
I have two columns with integers.
I need to sum this two columns, and if the value is 1 or greater, then sum 1, else 0.
How can I do this in DAX?
Thank you!
Example:
Column1 Column2 Result
1 1 1
0 0 0
0 1 1
1 0 1
- Anonymous6 years agoFinally, I solved with this dax expression:# CondicionalSum = CALCULATE(COUNT('Table1'[Column1]);FILTER('Table1';'Table1'[Column1] >= 1 ||'Table1'[Column2] >= 1))Thanks!
- Anonymous6 years ago
Finally I've changed it to PowerQuery with the following expression. The solution in DAX also works, but according to the link below, it's faster and better to use Power Query computed columns whenever the expression only depends on other columns of the same row of the table where you create the new column
PowerQuery Computed Column - The better choice
Column = if ([Column1]+[Column2]>0) then 1 else 0
DAX Calculated Column:
Column = if(Table1[Column1]+Table1[Column2]>0;1;0)
Thanks!!
https://www.sqlbi.com/articles/comparing-dax-calculated-columns-with-power-query-computed-columns/
10 Replies
- AnonymousNot applicable
Finally I've changed it to PowerQuery with the following expression. The solution in DAX also works, but according to the link below, it's faster and better to use Power Query computed columns whenever the expression only depends on other columns of the same row of the table where you create the new column
PowerQuery Computed Column - The better choice
Column = if ([Column1]+[Column2]>0) then 1 else 0
DAX Calculated Column:
Column = if(Table1[Column1]+Table1[Column2]>0;1;0)
Thanks!!
https://www.sqlbi.com/articles/comparing-dax-calculated-columns-with-power-query-computed-columns/
- AnonymousNot applicable
Hi ,
you can use this measure
Column = if( 'Table'[data1]+'Table'[data2]>0,1,0)Regards,
Husna
- AnonymousNot applicableFinally, I solved with this dax expression:# CondicionalSum = CALCULATE(COUNT('Table1'[Column1]);FILTER('Table1';'Table1'[Column1] >= 1 ||'Table1'[Column2] >= 1))Thanks!