cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kalavala
Frequent Visitor

DAX

How to write the formula  in DAX

Sum(Case When (columnname) < 10 Then 1 Else 0 End) Over (Partition By ColumnName)

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support
Community Support

Re: DAX

Hi @kalavala,

 

You can refer to below formual about the if statement:

1. Dax.

Calculate column:

Result =IF([columnname]<10,1,0) 

 

 

2. Power Query.

 if [columnname]<10 then 1 else 0

Full query:
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [ID] <10 then 1 else 0)

 

3.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

3 REPLIES 3
I_Like_Pi Resolver II
Resolver II

Re: DAX

Hopefully I am answering your question. I think you are looking for a column not a measure.

In the Data section select the appropriate table, and add a column with an IF statement similar to:

Tst_LT10 = IF(columnname<10, 1,0)

 

Now add a Table to a Report. Add the field you want to partition, the Tst_LT10 field you built, and some other extra field.

in the visualizations Section use the drop button next to Tst_LT10, and select Sum. Similarly use the Drop button on the extra field and select count. You should now have the count of rows that are less than 10 vs the count of rows in general.

 

If this is not what you are looking for please give a bit more detail.

Edit (Spell check)

 

kalavala
Frequent Visitor

Re: DAX

I am writing the if condition in queryeditior facing the below error can please help error.png

 

 

Community Support
Community Support

Re: DAX

Hi @kalavala,

 

You can refer to below formual about the if statement:

1. Dax.

Calculate column:

Result =IF([columnname]<10,1,0) 

 

 

2. Power Query.

 if [columnname]<10 then 1 else 0

Full query:
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [ID] <10 then 1 else 0)

 

3.PNG

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin Sheng
If this post helps, please consider Accept it as the solution to help the other members find it more quickly
Learning resources: Power BI

View solution in original post

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors