cancel
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.

Reply
Anonymous
Not applicable

Date change compare based on data version

Hi All,

I am very new to Power BI, but a long-time excel user.  I have spent a good deal of time reading and watching videos trying to solve what I think should be pretty straightforward, but no luck so far.  My dataset is rather large, but I believe this simplistic view will capture the basics of what I need.

 

Essentially, I have the production start schedule of a bunch of tools (ID).  I need to be able to see how those start schedules change based on the data version (instance) I pull.

 

The data version (instance) varies but is never more than one version per day.  In Power BI I am controlling the Instance I see with a slicer.  Here is a model of how the Table1 data is set up:

 

Table1

IDInstanceStartScheduleStartChange
12341/1/20215/5/2021 
12342/1/20215/5/20210
12343/1/20216/1/202127
12344/1/20216/1/20210
12345/1/20216/8/20217
50011/1/20214/3/2021 
50012/1/20216/1/202159
50013/1/20215/8/2021-24
50014/1/20216/12/202135
50015/1/20216/12/20210

 

One possible scenario in my report, I only select 2 Instances in the slicers, 1/1/2021 and 5/1/2021 and I want to see how those have changed:

Table1

IDInstanceStartScheduleStartChange
12341/1/20215/5/2021 
12345/1/20216/8/202134
50011/1/20214/3/2021 
50015/1/20216/12/202170

 

Another possible scenario in my report, I select 3 Instances in the slicers, 1/1/2021, 3/1/2021 and 5/1/2021 and I want to see how those have changed - each compared the last StartSchedule:

Table1

IDInstanceStartScheduleStartChange
12341/1/20215/5/2021 
12343/1/20216/1/202127
12345/1/20216/8/20217
50011/1/20214/3/2021 
50013/1/20215/8/202135
50015/1/20216/12/202135

 

How would a measure look that compares the Instances selected (in the slicers) and calculates the differences between the consecutive StartSchedules based on the ID?

 

Thanks!

Matt

2 ACCEPTED SOLUTIONS
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

New table:

Table 2 = VALUES('Table'[Instance])

Measure:

StartChange = 
VAR N1 =SELECTEDVALUE ( 'Table'[StartSchedule] )
VAR N2 =FILTER (
        ALL ( 'Table' ),
        'Table'[ID] = MAX ( 'Table'[ID] )
            && 'Table'[Instance] IN 'Table 2'
    )
VAR N3 =CALCULATE (
        MAX ( 'Table'[StartSchedule] ),
        TOPN (
            1,
            FILTER ( N2, [Instance] < SELECTEDVALUE ( 'Table'[Instance] ) ),
            [Instance], DESC
        )
    )
VAR N4 =IF ( ISBLANK ( N3 ), N1, N3 )
RETURN VALUE ( N1 - N4 )

vzhangti_0-1641286285067.pngvzhangti_1-1641286299162.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Hello @v-zhangti , that is great, works exactly as expected!  Is a great foundation for the problems I am looking to solve.

Thanks!

View solution in original post

7 REPLIES 7
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

New table:

Table 2 = VALUES('Table'[Instance])

Measure:

StartChange = 
VAR N1 =SELECTEDVALUE ( 'Table'[StartSchedule] )
VAR N2 =FILTER (
        ALL ( 'Table' ),
        'Table'[ID] = MAX ( 'Table'[ID] )
            && 'Table'[Instance] IN 'Table 2'
    )
VAR N3 =CALCULATE (
        MAX ( 'Table'[StartSchedule] ),
        TOPN (
            1,
            FILTER ( N2, [Instance] < SELECTEDVALUE ( 'Table'[Instance] ) ),
            [Instance], DESC
        )
    )
VAR N4 =IF ( ISBLANK ( N3 ), N1, N3 )
RETURN VALUE ( N1 - N4 )

vzhangti_0-1641286285067.pngvzhangti_1-1641286299162.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hello @v-zhangti , that is great, works exactly as expected!  Is a great foundation for the problems I am looking to solve.

Thanks!

Anonymous
Not applicable

Thank you Miguel!

 

I am struggling with this a bit.  Correct me if I am wrong, but the 'Table'[StartChange] should actually be 'Table'[StartSchedule], correct?  After I fix that, I get a value, but it is in the format of a date, like "4/21/2144", instead of 0 or empty if the dates didn't change.  I checked the formate of the Measure and it is set to whole number.  I checked both 'Table'[Instance] and 'Table'[StartSchedule], they are both set to short date.  What am l missing?

 

Thanks,

Matt



Hi @Anonymous,

 

I have copied your data to power BI and the column start change was the one with the whole numbers so was the one that I summed.

 

Maybe I have made the incorrect calculation but was the copy paste that you place on the initial post.

 

Can you share a print screen of the raw data  so I can compare  with what I did and give you the changes that are needed. 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix ,  

 

here is the raw data:

mkleinke_0-1641251024515.png

The "StartChange" is what I want the measure to do.  For example, 1234 Instance 3/1/21 vs. 2/2/21 is 27 days reviewing the StartSchedule difference.  Or for 5001 Instance 5/1/21 vs. 2/1/21 would be 11 days reviewing the StartSchedule difference.

 

Does that make sense?

 

Thanks again!

 

Matt

Hi @Anonymous,

 

Did not understood that the last column was the one you wanted to calculate. 

 

In this case and in order to increase the performance I would suggest create the column with the difference and the use a measure similar to mine to make the calcution based on selection. 

 

Do you want me to send the formula for the column or do you prefer to have everything calculated in a measure? 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Anonymous ,

 

Try the following measure:

 

StartChange Measure =
IF (
    ISBLANK ( SUM ( 'Table'[StartChange] ) ),
    "",
    SUMX (
        TOPN (
            2,
            FILTER (
                ALL ( 'Table'[ID], 'Table'[Instance], 'Table'[StartChange] ),
                'Table'[Instance] <= MAX ( 'Table'[Instance] )
                    && 'Table'[ID] = MAX ( 'Table'[ID] )
            ),
            'Table'[Instance], DESC
        ),
        'Table'[StartChange]
    )
)

 

Only using the IF statement because you have values that are blank and you want to present them in matrix. 

MFelix_0-1641213907063.png

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors