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
Aleksandra_MLT
Advocate I
Advocate I

Translate to M

Hey all. Can you help translating this to M ? This way I check level of data comepletenes so in one step I need to check if the value is not blank and also then divide by the number of columns checked:

 

Level1 = DIVIDE(
(IF ( ISBLANK ( TABLE1[Name] ), 0, 1 )
+ IF ( ISBLANK ( TABLE1[Description] ), 0, 1 )
+ IF ( ISBLANK (TABLE1[Alias] ), 0, 1 )
+ IF ( ISBLANK (TABLE1[Project required] ), 0, 1
) , 4)

1 ACCEPTED SOLUTION
ronrsnfld
Super User
Super User

If I understand your question correctly, you can

  1. Add an Index column to your table, so as to be able to define the row
  2. Using List.Accumulate, add a custom column with this formula (which counts the number of nulls and/or blanks and then computes the percentage of columns that are non-blank):

 

=1-
List.Accumulate({"Name","Description","Alias","Project required"},
                 0, 
                 (state, current)=>
                     if Record.Field(#"Added Index"{[Index]},current) = "" 
                        or Record.Field(#"Added Index"{[Index]},current) = null 
                        then state+1 else state)
     /4

 

View solution in original post

6 REPLIES 6
wdx223_Daniel
Super User
Super User

=Table.AddColumn(PreviousStepName,"Test",each List.Sum(List.Transform({"Name","Description","Alias","Project required"},(x)=>Byte.From(Record.FieldOrDefault(_,x,null)<>null)))/4)

v-angzheng-msft
Community Support
Community Support

Hi, @Aleksandra_MLT 

 

If I understand correctly, you want to check if there is a null value in the column.
You can first replace the blank value with null, and then use the List.NonNullCount

 

code:

= Table.ReplaceValue(#"Changed Type"," ",null,Replacer.ReplaceValue,{"Name", "Description", "Alias", "Project required"})
= Table.AddColumn(#"Replaced Value", "Custom", each Value.Divide(List.NonNullCount({[Name],[Description],[Alias],[Project required]}),4))

Result:

vangzhengmsft_1-1637308077717.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

ronrsnfld
Super User
Super User

If I understand your question correctly, you can

  1. Add an Index column to your table, so as to be able to define the row
  2. Using List.Accumulate, add a custom column with this formula (which counts the number of nulls and/or blanks and then computes the percentage of columns that are non-blank):

 

=1-
List.Accumulate({"Name","Description","Alias","Project required"},
                 0, 
                 (state, current)=>
                     if Record.Field(#"Added Index"{[Index]},current) = "" 
                        or Record.Field(#"Added Index"{[Index]},current) = null 
                        then state+1 else state)
     /4

 

Thank you, @ronrsnfld , your solution slows down PQ a lot and not sure if I'll implement it but the logic seems to work! 🙂

Here is a much faster method for the formula for the Custom Column (no Index column required):

 

List.Count(List.RemoveNulls(
             List.Transform(
               {[Name],[Description],[Alias],[Project Required]}, 
               each if _ = "" then null else _)))
               /4

 

Took a fraction of a second for 100,000 rows

Hi, @Aleksandra_MLT 

 

Is my answer above also helpful?

If @ronrsnfld 's reply is helpful to you, could you please mark it as Answered? It will help the others in the community find the solution easily if they face the same problem with you. 

 

 

Best Regards,
Community Support Team _ Zeon Zheng

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.

Top Solution Authors
Top Kudoed Authors