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
Anonymous
Not applicable

Count Months/Periods That have Data Starting M0

Hi Experts

 

I would like to count the number of Period (show as M0,M1,M2 etc...) in table blow. Similiar to how one would do a count in excel...for each row in the table. I have matrix table in Power BI extactly the same format...

 

So in row 20 we have data for 10 periods starting at M0 up until M9...

 

Capture.PNG

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please use the following formula in Power Query-->Add Custom Column:

=List.NonNullCount(List.Range(Record.FieldValues(_),2,11))

3.29.7.count in row.PNG

The whole M syntax is:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc7JCQAxCAXQXv45MK7ViP23MTExhzAMiAs81AgwBoifGUJCc7giR0BayK/QFnoL3cWXsTZ2jH3WeBM/pH6r61xJVsfIfAE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"#" = _t, Date = _t, M0 = _t, M1 = _t, M2 = _t, M3 = _t, M4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"#", Int64.Type}, {"Date", type date}, {"M0", Int64.Type}, {"M1", Int64.Type}, {"M2", Int64.Type}, {"M3", Int64.Type}, {"M4", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Period Length", each List.NonNullCount(List.Range(Record.FieldValues(_),2,11)))
in
    #"Added Custom"

 

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

View solution in original post

6 REPLIES 6
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please use the following formula in Power Query-->Add Custom Column:

=List.NonNullCount(List.Range(Record.FieldValues(_),2,11))

3.29.7.count in row.PNG

The whole M syntax is:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("dc7JCQAxCAXQXv45MK7ViP23MTExhzAMiAs81AgwBoifGUJCc7giR0BayK/QFnoL3cWXsTZ2jH3WeBM/pH6r61xJVsfIfAE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"#" = _t, Date = _t, M0 = _t, M1 = _t, M2 = _t, M3 = _t, M4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"#", Int64.Type}, {"Date", type date}, {"M0", Int64.Type}, {"M1", Int64.Type}, {"M2", Int64.Type}, {"M3", Int64.Type}, {"M4", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Period Length", each List.NonNullCount(List.Range(Record.FieldValues(_),2,11)))
in
    #"Added Custom"

 

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

Anonymous
Not applicable

Hi Eyelyn9... could kindly cast your eye over

https://community.powerbi.com/t5/Desktop/TRICKY-Custom-Column-in-Power-Query/m-p/1760455#M690967

 

Everyone on community forum is struggling 

Anonymous
Not applicable
Anonymous
Not applicable

many thanks Eyelyn Qin, much appericated

amitchandak
Super User
Super User

@Anonymous ,The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Anonymous
Not applicable

Hi Amit...

How do you count at row level for each period from M0 onwards i.e. for row 20. that coun is 10 because we have values in period M0-M9... 

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.