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
    • Overview
    • Find consulting services
    • Partner showcase
    • Find a partner
    • Become a partner
    • Instructor-led training
    • Getting started
      • Overview
      • Online workshops
      • 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
    • 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
    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: 
    • Microsoft Power BI Community
    • Galleries
    • Quick Measures Gallery
    • Power BI - DAX Offset Function

    Power BI - DAX Offset Function

    02-20-2023 01:25 AM

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

    Power BI - DAX Offset Function

    ‎02-20-2023 01:25 AM

    Power BI — Offset Function

    amitchandak_0-1676884958990.jpeg

     

    The OFFSET function retrieves a result based on the relative positioning of the data

    The offset function returns a single row that is positioned either before or after the current row, within the specified partition, sorted in the specified order, based on the offset provided. If the current row cannot be deduced to a single row for whatever reason, multiple rows will be returned.

    Instead of being pushed to the data source, DAX functions like Offset are executed within the DAX engine. These DAX functions have shown significantly improved performance compared to existing DAX expressions, particularly when sorting non-continuous columns is necessary.

    OFFSET ( <delta/Number>, <relation/Table expression>, <order By from relation>, <blanks>, <partition By relation> )

    Model: I am using the standard sales model, which I am using for all my videos and blogs. Sales fact with a key measure [net], joined with dimensions: Item, Geography, Date, and Customer.

    amitchandak_1-1676884958974.png

     

    Let us create a visual using the item category and net. We will also create our first offset measure Last Category and add to it. 

    amitchandak_2-1676884958992.png

     

    Measure used. Also adding the next category

    Last Category = CALCULATE([net], OFFSET(-1, ALLSELECTED(‘Item’[Category]), ORDERBY(‘Item’[Category],asc)))
    Next Category = CALCULATE([net], OFFSET(1, ALLSELECTED('Item'[Category]), ORDERBY('Item'[Category],asc)))

    Once you add the brand to a visual, this measure will not work as expected as it is still looking for the order based on category

    amitchandak_3-1676884959008.png

     

    We will need a new set of measures 

    Last Category Brand = CALCULATE([net], OFFSET(-1, ALLSELECTED('Item'[Brand],'Item'[Category]), ORDERBY('Item'[Category],asc),KEEP,PARTITIONBY('Item'[Brand])))
    Next Category Brand = CALCULATE([net], OFFSET(1, ALLSELECTED('Item'[Brand],'Item'[Category]), ORDERBY('Item'[Category],asc),KEEP,PARTITIONBY('Item'[Brand])))
    amitchandak_4-1676884959396.png

     

    This is how we can get time intelligence. The default sort column will not work. We have to use sort column in relation and order by

    Offset Previous Month = CALCULATE([Net],OFFSET(-1, ALL('Date'[Month Year sort],'Date'[Month Year]),ORDERBY('Date'[Month Year sort]))) 

    In case we want the previous month in the same year 

    Previous Month in Year = CALCULATE([Net],OFFSET(-1, ALL('Date'[Month Year sort],'Date'[Month Year],'Date'[Year],'Date'[Qtr Year]),ORDERBY('Date'[Month Year sort]),KEEP,PARTITIONBY('Date'[Year]))) 
    amitchandak_5-1676884959253.png

     

    One can create a combined measure for previous values like

    Previouse Value = SWITCH(TRUE(),
    ISINSCOPE('Date'[Date]), CALCULATE([Net], OFFSET(-1, ALL('Date'[Date]))),
    ISINSCOPE('Date'[Month Year]), CALCULATE([Net],OFFSET(-1, ALL('Date'[Month Year sort],'Date'[Month Year],'Date'[Year],'Date'[Qtr Year]),ORDERBY('Date'[Month Year sort]))),
    ISINSCOPE('Date'[Qtr Year]),CALCULATE([Net], OFFSET(-1, ALL('Date'[Year], 'Date'[Qtr Year]))),
    ISINSCOPE('Date'[Year]), CALCULATE([Net],OFFSET(-1, ALL('Date'[Year])))
    )
    amitchandak_6-1676884959473.png

     

    You can find the video below

     

    Free Microsoft Power BI Course for Beginners, 2023

     

    My Medium blogs can be found here if you are interested

    Click here to access all my blogs and videos in a jiffy via an exclusive glossary using Power BI. Please like, share, and comment on these blogs. I would appreciate your suggestions for improvement, challenges, and suggestions for topics so that I can explore these in more depth.

    In addition, I have over 500 videos on my YouTube channel that are related to Power BI, Tableau, and Incorta. With the help of these videos, you will learn hundreds of DAX and Power Query functions, in addition to hundreds of Power BI, use cases that will assist you in becoming an expert in Power BI. Make sure you subscribe, like, and share it with your friends.

    Master Power BI
    Expertise in Power BI
    Power BI For Tableau User
    DAX for SQL Users
    Learn SQL



    Microsoft Power BI Learning Resources, 2023 !!
    Learn Power BI - Full Course with Dec-2022, with Window, Index, Offset, 100+ Topics !!
    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
    Formatted Profit and Loss Statement with empty lines
    AT offset.pbix
    Labels:
    • Labels:
    • Financial
    • Mathematical
    • Other
    • Time Intelligence
    Message 1 of 1
    993 Views
    0
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic

    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
    California Consumer Privacy Act (CCPA) Opt-Out Icon Your California Privacy Choices