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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Using OFFSET (and partition) to subtract row values that are grouped

Hello PowerBI Community,

 

I would like to use the new OFFSET function in order to find the difference between two dates, but within groups. I think the OFFSET (with partition) would be ideal but I cannot get it to work.

 

The data is as follows:

 

cjps_0-1674010450025.png

 

The output I am after is that;

 

Row 1 & 2, "Forecast - Baseline" should read the difference between the 23/5/2023 and 22/3/2023, i.e: x63 days

Row 3 & 4, "Forecast - Baseline" should read the difference between the 21/6/2024 and 21/6/2024, i.e: x0 days

Row 5 & 6, "Forecast - Baseline" should read the difference between the 24/10/2024 and 30/10/2024, i.e: x7 days

 

I have spent a number of days on this (I am just starting off with PowerBI) and the closest DAX I wrote was as follows;

 

cjps_1-1674010767321.png

 

I get a circular dependency error, amongst other errors with other methods.

 

I would prefer to attach the PowerBI file but can't seem to find how to do this?

 

I hope someone can help me, thanks very much.


Regards, Chris.



1 ACCEPTED SOLUTION

Hi,

Thank you for your message.

Please check the below picture and the attached pbix file.

If you want to see the results that are higher than zero, please try using ABS DAX function together.

 

Jihwan_Kim_0-1674021364218.png

 

Forecast-Baseline CC = 
VAR _offsetresult =
    MAXX (
        OFFSET (
            -1,
            SUMMARIZE ( Matrix, Matrix[CIM #], Matrix[Date Dataset], Matrix[Date] ),
            ORDERBY ( Matrix[Date Dataset], ASC ),
            KEEP,
            PARTITIONBY ( Matrix[CIM #] )
        ),
        Matrix[Date]
    )
VAR _offsetresultreverse =
    MAXX (
        OFFSET (
            -1,
            SUMMARIZE ( Matrix, Matrix[CIM #], Matrix[Date Dataset], Matrix[Date] ),
            ORDERBY ( Matrix[Date Dataset], DESC ),
            KEEP,
            PARTITIONBY ( Matrix[CIM #] )
        ),
        Matrix[Date]
    )
RETURN
    IF ( _offsetresult <> BLANK (), DATEDIFF ( _offsetresult, Matrix[Date], DAY ), DATEDIFF (  Matrix[Date], _offsetresultreverse, DAY )  )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi Jihwan_Kim,

That is great. Is there a way to have the values in the blank cells as well, i.e: 62 in Row 1 & Row 2, 0 in Row 3 & Row 4, etc. I expect I need this when I create the line chart.

Regards, Chris.

Hi,

Thank you for your message.

Please check the below picture and the attached pbix file.

If you want to see the results that are higher than zero, please try using ABS DAX function together.

 

Jihwan_Kim_0-1674021364218.png

 

Forecast-Baseline CC = 
VAR _offsetresult =
    MAXX (
        OFFSET (
            -1,
            SUMMARIZE ( Matrix, Matrix[CIM #], Matrix[Date Dataset], Matrix[Date] ),
            ORDERBY ( Matrix[Date Dataset], ASC ),
            KEEP,
            PARTITIONBY ( Matrix[CIM #] )
        ),
        Matrix[Date]
    )
VAR _offsetresultreverse =
    MAXX (
        OFFSET (
            -1,
            SUMMARIZE ( Matrix, Matrix[CIM #], Matrix[Date Dataset], Matrix[Date] ),
            ORDERBY ( Matrix[Date Dataset], DESC ),
            KEEP,
            PARTITIONBY ( Matrix[CIM #] )
        ),
        Matrix[Date]
    )
RETURN
    IF ( _offsetresult <> BLANK (), DATEDIFF ( _offsetresult, Matrix[Date], DAY ), DATEDIFF (  Matrix[Date], _offsetresultreverse, DAY )  )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Anonymous
Not applicable

Hello PowerBI community,

 

The solution above is correct (thanks Jihwan_Kim!), but in incorporating the real data I have uncovered another problem I am hoping I could get some help with.

 

The intent of this graph is to show the slip/gain or neutral status of project milestones (in reality there would be a lot more more than three).

 

The lines are now correctly being formatted if the milestone slips (red), stays the same/neutral (grey) or is brought forward/gain (green)

 

What is happening now is that if a date of a line moves past another line/dot, it splits up the line. The first picture is correct (with limited sample data), but if I move the end date of the red line past the 21/6/2024 (the grey dot) the line splits into two dots.

 

cjps_0-1674084485421.pngcjps_1-1674084539836.png

As an aside, if anyone can tell me how to upload the *.pbix file, I am happy to share it.

 

Thanks for your help.

 

Regards, Chris.

 

Anonymous
Not applicable

Amazing Jihwan_Kim, thank you so much for your help.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1674017173895.png

 

 

Forecast-Baseline CC =
VAR _offsetresult =
    MAXX (
        OFFSET (
            -1,
            SUMMARIZE ( Matrix, Matrix[CIM #], Matrix[Date Dataset], Matrix[Date] ),
            ORDERBY ( Matrix[Date Dataset], ASC ),
            KEEP,
            PARTITIONBY ( Matrix[CIM #] )
        ),
        Matrix[Date]
    )
RETURN
    IF ( _offsetresult <> BLANK (), DATEDIFF ( _offsetresult, Matrix[Date], DAY ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.