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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


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.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors