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
saipawar
Helper IV
Helper IV

How to calculate count of each value in a column and split it into new columns?

Hi

I have data that looks like the below table. Note that there are blanks in 'Content Name'

Published DateContent Name
1/3/2020JAN - hybrid installs

 

2/2/2020

FEB - KPIS
2/23/2020FEB - SD WAN
2/24/2020 
2/25/2020Not launch related
2/25/2020Not launch related
4/1/2020APR - Mimics
7/3/2020JUL - Hiking 
7/18/2020 
10/14/2020OCT - qwerty
10/14/2020

Not launch related

 

I added a conditional column to bucketise Column Name, here's the output - 

Published DateContent NameContent Type
1/3/2020JAN - hybrid installsLaunch Related

 

2/2/2020

FEB - KPISLaunch Related
2/23/2020FEB - SD WANLaunch Related
2/24/2020  
2/25/2020Not launch relatedNot launch related
2/25/2020Not launch relatedNot launch related
4/1/2020APR - MimicsLaunch Related
7/3/2020JUL - Hiking Launch Related
7/18/2020  
10/14/2020OCT - qwertyLaunch Related
10/14/2020

Not launch related

Not launch related

 

Now, further I want to calculate the count of "Content Type" and look at it monthly.

 

Here's the desired output - Note that nulls/blanks are to be ignored but NOT removed from the data

Month (taken from Published date)Launch RelatedNot Launch related
Jan10
Feb22
April10
July10
October11

 

How can this output be achieved?

Thanks

1 ACCEPTED SOLUTION

@saipawar
If you already have the conditional column, then I think your question is more related to desktop, all the Power Query work is complete.

Just create a matrix visualization and put your new Content Type column in Columns, Month in Rows (assuming you have a DimDate table that relates to Published date), and Content Name in Values with a summarization set to Count.

 

@saipawar UPDATE: Here is my result using the sample data you provided: 

AllisonKennedy_0-1599996286543.png

Note the filter on Content Type and the Values summarization is set to 'Count of Content Name'

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@saipawar 

Hope this is the output you are expecting?

Fowmy_0-1599980350650.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pdBNC4IwGMDxr/KwszHforNl0YuZqNFBPPgycjRn6ST89o1KMNBTxz37/ce2KEJemzLaFCQHOxEEKWhVcUG4ADcph8uwuxMUKxHSsIF1VVfl3t5yYQZFl9Y0B8obkTDWyLmTtDwrwCdMHpm/Kx3rfbVZL2V18HbBJDV+bWDDxXIn9bzXbiWAfUj9JaPDfzoTa31meb683JGWNJt49WLwV2dH4i29UX6Fca2pWDN7f1qF0j+epBbdCI9f", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]),
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Published Date", type date}}),
    #"Inserted Month Name" = Table.AddColumn(#"Changed Type", "Month Name", each Date.MonthName([Published Date]), type text),
    #"Removed Other Columns" = Table.SelectColumns(#"Inserted Month Name",{"Content Type", "Month Name"}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Removed Other Columns", "Content Type", "Content Type - Copy"),
    #"Pivoted Column" = Table.Pivot(#"Duplicated Column", List.Distinct(#"Duplicated Column"[#"Content Type"]), "Content Type", "Content Type - Copy", List.Count)
in
    #"Pivoted Column"

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

ImkeF
Super User
Super User

Hi @saipawar ,

I would add a column with 0 or 1 and create a sum instead. 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@ImkeF If I create a column with 0 and 1, how can I split them into 2 different columns later to match the desired output?

Hi @saipawar ,

I believe adding 2 columns instead, one for each should be an option.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

@saipawar
If you already have the conditional column, then I think your question is more related to desktop, all the Power Query work is complete.

Just create a matrix visualization and put your new Content Type column in Columns, Month in Rows (assuming you have a DimDate table that relates to Published date), and Content Name in Values with a summarization set to Count.

 

@saipawar UPDATE: Here is my result using the sample data you provided: 

AllisonKennedy_0-1599996286543.png

Note the filter on Content Type and the Values summarization is set to 'Count of Content Name'

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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