• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Showing items with no data in a pivot|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Showing items with no data in a pivot|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryShowing items with no data in a piv…
sp_PrintTopic sp_TopicIcon
Showing items with no data in a pivot
Avatar
k s
Member
Members
Level 0
Forum Posts: 12
Member Since:
December 8, 2020
sp_UserOfflineSmall Offline
1
June 23, 2021 - 11:16 pm
sp_Permalink sp_Print

Hello I was just looking at your newsletter on showing items in PivotTables with no data and video here, and wondered if anyone knows a way to do the same when pivoting data with Power Query.  

 

Suppose I have a table with data like this below which could have scores between 1-7 

Idea Score Before Score After
Idea 1 1 2
Idea 1 1 2
Idea 1 5 3
Idea 1 5 7
Idea 1 3 4
Idea 1 3 6
Idea 1 2 4
Idea 1 4 4
Idea 1 4 4
Idea 2 3 1
Idea 2 4 2

 

...and wanted to count the number of times when a "before" and after "score" change for each permutation.  For the data above, I can produces a table like this, using the pivot approach I've taken with the M code at the bottom: 

Idea Score Before 1 2 3 4 6 7
Idea 1 1   2        
Idea 1 2       1    
Idea 1 3       1 1  
Idea 1 4       2    
Idea 1 5     1     1
Idea 2 3 1          
Idea 2 4   1        

...but as you can see it doesn't include score "5" in the columns or 6 & 7 in the rows (for Idea 1).  I'd like to make a table which includes all permutations 1-7.  Is there a simple way to do this? 

 

I've generated the above example using this code below: 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8kxJTVQwVNJRAmEjpVgd/EKmQGyMKWSOKmQMxCaYQmaoQkaYqkwIChlBzTJEFTKBODUWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Idea = _t, #"Score Before" = _t, #"Score After" = _t]),

#"Changed Type" = Table.TransformColumnTypes(Source,{{"Idea", type text}, {"Score Before", Int64.Type}, {"Score After", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Index", each 1, type number),

#"Pivoted Column" = Table.Pivot(
Table.TransformColumnTypes(#"Added Custom", {{"Score After", type text}}),

List.Sort(
List.Distinct(
Table.TransformColumnTypes(
#"Added Custom", {{"Score After", type text}}
)[Score After]
), Order.Ascending
),
"Score After", "Index", List.Sum
)
in
#"Pivoted Column"

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1824
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
June 25, 2021 - 3:13 pm
sp_Permalink sp_Print

Hi,

PQ will automatically detect column names from the Score After column values, using List.Distinct.

You can replace this code from #"Pivoted Column" step:
List.Sort(
List.Distinct(
Table.TransformColumnTypes(
#"Added Custom", {{"Score After", type text}}
)[Score After]
), Order.Ascending
)

with your custom list of columns:

List.Transform({1..7},Text.From)

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Mynda Treacy
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 215
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Anthony van Riessen
Erlinda Eloriaga
Abisola Ogundele
MARTYN STERRY
Rahim Lakhani
Ngoc Qui Nguyen
Clement Mansfield
Rose .
Bindu Menon
Baruch Zemer
Forum Stats:
Groups: 3
Forums: 24
Topics: 6352
Posts: 27779

 

Member Stats:
Guest Posters: 49
Members: 32319
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.