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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
decarsul
Helper IV
Helper IV

DAX count / SUM with IF expressions

Hi there!

 

Recently i've been tasked to switch some dashboards over to PowerBI (not desktop), from excel. This means i have to work with DAX, which i've not worked with much. So i'm hoping you all can help me!

 

The case:

I have a data set which is an external export of a question form.

These questions can be answered with Yes, No and N/A. And are saved as varchar. 

The value NO needs to be summed up to a total, but not for the entire row, only for specific columns within the row.

 

What i know i can do:

I can replace all NO value's for the specific columns to 1's and simply do a sum or count on them. (this will be negative for other calculated columns)

I can create a integer column copy of each of the source columns, and create a sum on them. Using the If statements below. (this would create inefficiency to my knowledge)

 

What i'm looking to do:

Create a nested 'count.if' within dax. I have already determined that the IF statement gives the proper result. This is also how i would create the extra columns.

 

Data sample:

IF('Form'[50104]="NO";1;0)
IF('Form'[50107]="NO";1;0)
IF('Form'[50301]="NO";1;0)
IF('Form'[50305]="NO";1;0)
IF('Form'[50401]="NO";1;0)

 

Any help would be appreciated!

1 ACCEPTED SOLUTION
decarsul
Helper IV
Helper IV

Update:

So after 2 days and a fresh cup of coffee, i figured out i simply made a typo in the column header names.

Now its just a string of if statements with a + in between. This works.

 

But there is probably a more efficient way?

View solution in original post

2 REPLIES 2
v-shex-msft
Community Support
Community Support

Hi @decarsul ,

I'd like to suggest you to enter to query editor and enable 'unpivoted columns' on your fields, then you can write simple if statement formulas to check all fields.

Unpivot columns (Power Query)

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
decarsul
Helper IV
Helper IV

Update:

So after 2 days and a fresh cup of coffee, i figured out i simply made a typo in the column header names.

Now its just a string of if statements with a + in between. This works.

 

But there is probably a more efficient way?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.