Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
jbetkowskawbd
Frequent Visitor

Offset function combined with field parameter

Hello,

 

I would like to create a table that will show a change between 2 dates but requirement from the user is to be able to dynamically change time perspective view - so they would like to compare year to year / month to month / week to week / quarter to quarter / day over day. Since there is also week over week needed I cannot use built in time intelligence function. Till now I used additional table with dynamic date selection, however I thought that maybe it will be possible to write a metric with offset function and in the table itselt I could use field parameter. I created it but received info: Column [] is part of composite key, but not all columns of the composite key are included in the expression or its dependent expression.
My metric is written as follows:

 

Total Change = 
VAR Offset = 
CALCULATE(
    [Total],
    OFFSET(
        -1,
        ALLSELECTED('Dynamic Date Selection'[Dynamic Date Selection]),
        ORDERBY('Dynamic Date Selection'[Dynamic Date Selection], ASC)
        )
    )
VAR PoPChange = 
([Total] - 
CALCULATE(
    [Total],
    OFFSET(
        -1,
        ALLSELECTED('Dynamic Date Selection'[Dynamic Date Selection]),
        ORDERBY('Dynamic Date Selection'[Dynamic Date Selection], ASC)
        )
    )) / CALCULATE(
    [Total],
    OFFSET(
        -1,
        ALLSELECTED('Dynamic Date Selection'[Dynamic Date Selection]),
        ORDERBY('Dynamic Date Selection'[Dynamic Date Selection], ASC)
        )
    )
    VAR Result = IF(NOT ISBLANK(Offset), PoPChange)
    Return
    Result

 

 

Dynamic date selection is a table created by using field parameter function:
|

 

Dynamic Date Selection = {
    ("calendar_date", NAMEOF('calendar'[calendar_date]), 0),
    ("week_end_date", NAMEOF('calendar'[week_end_date]), 1),
    ("month_end_date", NAMEOF('calendar'[month_end_date]), 2),
    ("year_no", NAMEOF('calendar'[year_no]), 3)
}

 

 

Is it even possible to make changes in Change metric to be able to use it in table with field parameter in rows?

3 REPLIES 3
jbetkowskawbd
Frequent Visitor

Here you can find powerbi file and excel with sample data.

 

https://www.dropbox.com/scl/fo/naasx1kq80ucpxw9o93oc/h?rlkey=mswsz1c7lgmwh1p98qh3t5fku&dl=0

 

Currently I have achieved what was wanted by creating additional dax table and using bookmarks.

However I just wanted to refactor this as I noticed that Field parameter option which I thought is more simple and more elegant.

Your Calendar table has gaps

 

lbendlin_0-1696608750855.png

 

You also didn't specify the four digit years so Power BI got confused.

 

lbendlin_1-1696609514133.png

 

 

I'd recommend you fix that table first.

 

lbendlin
Super User
Super User

This happens when you sort one column by another column (frequently done in Calendar tables).  The sort column needs to be part of the calculation.

 

Might need to use a SWITCH statement to handle the different scenarios.  It kinda defeats the purpose of the Field Parameters, but that's something you can recover from.

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors