+ Reply to Thread
Results 1 to 10 of 10

Pivot Table from SQL tabel - how to work with boolean fields

  1. #1
    Registered User
    Join Date
    02-18-2015
    Location
    Fr
    MS-Off Ver
    2013
    Posts
    14

    Pivot Table from SQL tabel - how to work with boolean fields

    Dear Excel gurus,
    I'm fairly new to pivot table and I'm trying to show some statistics from data stored in a MSSQL table. It's working great so far except that I have a lot of PASS/FAIL columns that contain either TRUE or FALSE (type is 'bit' in MSSQL) and I would like to display a PASS percentage.

    I've tried adding calculated fields to convert this to 0/1 but I'm hitting a wall. Google did not help neither.
    Is there a way I can convert booleans?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    Have you tried converting TRUE/FALSE to 1/0 in a query based on the MSSql table?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-18-2015
    Location
    Fr
    MS-Off Ver
    2013
    Posts
    14

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    Hi, thanks for looking into my issue.
    Unfortunately I can't alter the MSSQL table, if this is one you mean.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    I'm not suggesting you alter the table, I'm suggesting you use a query to get the data from the table and in that query convert the TRUE/FALSE field(s) to 1/0.

    How are you currently getting the data from table?

  5. #5
    Registered User
    Join Date
    02-18-2015
    Location
    Fr
    MS-Off Ver
    2013
    Posts
    14

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    Yes, but I'm doing this with the Excel "wizard" (wihen adding a data source 'from SQL server') so I did now wrote the SQL query by myself.
    How can I modify the query?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    Normally you would use CAST,

    SELECT column1, column2, ..., CAST(bitcolumn AS INT)
    FROM MyTable

    not sure how that would work with the wizard.

  7. #7
    Registered User
    Join Date
    02-18-2015
    Location
    Fr
    MS-Off Ver
    2013
    Posts
    14

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    So I should probabyl create a new Connection. But how can I create a SQL connection that will let me input the query?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    Do you not get the option to return the data to MS Query?

    Or when you look at the query properties is there not a field for CommandText, or something similar?

    PS Not used SQL Server with Excel for a while, hence the vagueness.

  9. #9
    Registered User
    Join Date
    02-18-2015
    Location
    Fr
    MS-Off Ver
    2013
    Posts
    14

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    Ok I've managed to work something out. Thanks for your help
    Is there a simpler solution that addin the CAST command to all my collumns? (simpler query)
    Also it looks like th PowerPivot addin can handle data conversion on the fly, are there other free addin that would do that?

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Pivot Table from SQL tabel - how to work with boolean fields

    You could do the conversion in Excel with simple formulas adjacent to the raw data and then you could use the results of those formulas as the base for the pivot table.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Pivot tabel code adds xlsum values as row fields
    By pdalal in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-11-2014, 10:36 AM
  2. Collapse/Expand - Pivot table Fields - Need equivalent option in Excel VBA Pivot table
    By ragavendraph in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-07-2012, 03:00 PM
  3. How to Disable automatic fields in pivot table like total and count on fields
    By anushka in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-24-2009, 07:53 AM
  4. Differentiate between column fields and data fields in a pivot table
    By whiteheadw in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2009, 01:59 PM
  5. Pivot table grouping of dates in row fields will not work. Why?
    By Bill B in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-09-2005, 08:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1