skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Microsoft 365 + Power BI
    • Dynamics 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Partners Overview
    • Solutions Partners
    • BI Specialized Partners
    • Power BI CSOs
    • Fabric Partner Community
    • Training
    • Getting started
      • Overview
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Power BI forums
    • Updates
    • News & Announcements
    • Get Help with Power BI
    • Desktop
    • Service
    • Report Server
    • Power Query
    • Mobile Apps
    • Developer
    • DAX Commands and Tips
    • Custom Visuals Development Discussion
    • Health and Life Sciences
    • Power BI Spanish forums
    • Translated Spanish Desktop
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Training and Consulting
    • Instructor Led Training
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Events
    • Ideas
    • Custom Visuals Ideas
    • Issues
    • Issues
    • Events
    • Upcoming Events
    • Community Engagement
    • T-Shirt Design Challenge 2023
    • Community Blog
    • Power BI Community Blog
    • Custom Visuals Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 

    Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

    • Power BI forums
    • Galleries
    • Quick Measures Gallery
    • XBITXOR

    XBITXOR

    09-20-2023 11:12 AM - last edited 09-26-2023 12:50 PM

    Super User Greg_Deckler
    Super User
    584 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    XBITXOR

    ‎09-20-2023 11:12 AM

    It's BITXOR but for multiple rows.

     

    XBITXOR = 
        VAR __RowCount = COUNTROWS('bitor')
        VAR __Length = LEN(MAX('bitor'[day_of_month_bit_position]))
        VAR __String = CONCATENATEX('bitor', [day_of_month_bit_position])
        VAR __Table = 
                ADDCOLUMNS(
                    GENERATESERIES(0, __RowCount * __Length - 1),
                    "__Bit", MID(__String, [Value]+1, 1) + 0,
                    "__Mod", MOD([Value], __Length)
                )
        VAR __Table1 = 
            ADDCOLUMNS(
                GENERATESERIES(0, __Length - 1),
                "__BITXOR", 
                        VAR __Index = [Value]
                        VAR __Sum = SUMX(FILTER(__Table, [__Mod] = __Index),[__Bit])
                        VAR __Result = IF(__Sum = 1, 1, 0)
                    RETURN
                        __Result
            )
    RETURN
        CONCATENATEX(__Table1, [__BITXOR],,[Value],ASC)

     

     

    eyJrIjoiYjI5NTljYTYtZDlmMi00MmNjLWFiOWYtMmE0Nzc2ZGUyODQ1IiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ me in replies or I'll lose your thread!!!
    Instead of a Kudo, please vote for this idea
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    XBITXOR.pbix
    Labels:
    • Labels:
    • Mathematical
    • Other
    Message 1 of 6
    584 Views
    0
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    AlexisOlson
    Super User AlexisOlson
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎09-26-2023 09:57 AM

    @Greg_Deckler I think you're a bit off somewhere. For example, shouldn't customer_3, month 1 have 1 as the last digit?

     

    Here's my attempt:

    XBITOR = 
    VAR _BitStrings_ = DISTINCT ( 'bitor'[day_of_month_bit_position] )
    VAR _Length = MAXX ( _BitStrings_, LEN ( 'bitor'[day_of_month_bit_position] ) )
    VAR _BITOR_ =
        ADDCOLUMNS (
            GENERATESERIES ( 1, _Length ),
            "@Bit",
                MAXX (
                    _BitStrings_,
                    MID ( 'bitor'[day_of_month_bit_position], [Value], 1 )
                )
        )
    VAR _ToString = CONCATENATEX ( _BITOR_, [@Bit], "", [Value] )
    RETURN
        _ToString
    Message 2 of 6
    484 Views
    2
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to AlexisOlson
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎09-26-2023 12:52 PM

     Yeah, there was an original logic error in XBITOR that I fixed on XBITOR and XBITAND but hadn't gotten around to XBITXOR yet. It's a really simple fix that involves the following two lines of code (both GENERATESERIES). I updated everything.

     GENERATESERIES(0, __RowCount * __Length - 1)

    and

    GENERATESERIES(0, __Length - 1),

     

    @AlexisOlson


    @ me in replies or I'll lose your thread!!!
    Instead of a Kudo, please vote for this idea
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Message 5 of 6
    458 Views
    0
    Reply
    AlexisOlson
    Super User AlexisOlson
    Super User
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎09-26-2023 02:05 PM

    Nice.

     

    I just realized that I posted my XBITOR in the XBITXOR thread.

     

    For XBITXOR, you do need to use the sum logic like you have instead of a simple MAXX for XBITOR and MINX for XBITAND:

     

    XBITXOR = 
    VAR _BitStrings_ =
        SELECTCOLUMNS (
            DISTINCT ( 'bitor'[Pos] ),
            "@BitStr", 'bitor'[Pos]
        )
    VAR _Length = MAXX ( ALLSELECTED ( 'bitor' ), LEN ( 'bitor'[Pos] ) )
    VAR _Padded_ =
        ADDCOLUMNS (
            _BitStrings_,
            "@Padded", REPT ( "0", _Length - LEN ( [@BitStr] ) ) & [@BitStr]
        )
    VAR _BITOR_ =
        ADDCOLUMNS (
            GENERATESERIES ( 1, _Length ),
            "@Bit",
                VAR _Sum = SUMX ( _Padded_, INT ( MID ( [@Padded], [Value], 1 ) ) )
                VAR _Result = IF ( _Sum = 1, "1", "0" )
                RETURN
                    _Result
        )
    VAR _ToString = CONCATENATEX ( _BITOR_, [@Bit], "", [Value] )
    RETURN
        _ToString

     

    Message 6 of 6
    449 Views
    2
    Reply
    AlexisOlson
    Super User AlexisOlson
    Super User
    In response to AlexisOlson
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎09-26-2023 10:23 AM

    If the bit strings are not all the same length, then you probably want to left pad with zeros like this:

    XBITOR = 
    VAR _BitStrings_ =
        SELECTCOLUMNS (
            DISTINCT ( 'bitor'[Pos] ),
            "@BitStr", 'bitor'[Pos]
        )
    VAR _Length = MAXX ( ALLSELECTED ( 'bitor' ), LEN ( 'bitor'[Pos] ) )
    VAR _Padded_ =
        ADDCOLUMNS (
            _BitStrings_,
            "@Padded", REPT ( "0", _Length - LEN ( [@BitStr] ) ) & [@BitStr]
        )
    VAR _BITOR_ =
        ADDCOLUMNS (
            GENERATESERIES ( 1, _Length ),
            "@Bit", MAXX ( _Padded_, MID ( [@Padded], [Value], 1 ) )
        )
    VAR _ToString = CONCATENATEX ( _BITOR_, [@Bit], "", [Value] )
    RETURN
        _ToString
    Message 3 of 6
    475 Views
    2
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to AlexisOlson
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    ‎09-27-2023 05:01 AM

    @AlexisOlson I like the idea of padding for instances of having different lengths of bits.


    @ me in replies or I'll lose your thread!!!
    Instead of a Kudo, please vote for this idea
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Mastering Power BI 2nd Edition

    DAX is easy, CALCULATE makes DAX hard...
    Message 4 of 6
    422 Views
    0
    Reply

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2023 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    Consumer Privacy Act (CCPA) Opt-Out Icon Your Privacy Choices