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

Counting Across Columns?

In my query editor, I have these columns. The column names differ, but the values are all the same:

1.PNG

 

I'm trying to find a way to get the counts of the values without unpivoting. I've already unpivoted this data before which makes everything easy to count, but it does not allow me to calculate averages over time and things of that nature correctly once it is unpivoted. How else could I get a count of each value?

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

HI @Anonymous,

 

You can refer to below formula to transform table as group result.

 

Power query custom function:

 

let
    Groupping= (source as table) => 
    let
        Source= Text.Split(Text.Combine(Table.ToList(source),","),","),
        Transformed=Table.FromList(List.Distinct(Source),Splitter.SplitByNothing(),{"Item"}),
        Output = Table.AddColumn(Transformed,"Count", each Function.Invoke((x)=> List.Count(List.Select(Source, each _ = x)),{_[Item]}))
    in
        Output
in    
    Groupping

27.gif

 

 

Notice: my function not works for value with date format, please convert date type as text before invoke.

 

Regards,

Xiaoxin Sheng

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

View solution in original post

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

HI @Anonymous,

 

You can refer to below formula to transform table as group result.

 

Power query custom function:

 

let
    Groupping= (source as table) => 
    let
        Source= Text.Split(Text.Combine(Table.ToList(source),","),","),
        Transformed=Table.FromList(List.Distinct(Source),Splitter.SplitByNothing(),{"Item"}),
        Output = Table.AddColumn(Transformed,"Count", each Function.Invoke((x)=> List.Count(List.Select(Source, each _ = x)),{_[Item]}))
    in
        Output
in    
    Groupping

27.gif

 

 

Notice: my function not works for value with date format, please convert date type as text before invoke.

 

Regards,

Xiaoxin Sheng

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

@v-shex-msft thank you! This is a bit over my head but I will give it a try.

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.