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
chrismpbi
Frequent Visitor

Dax Date Comparison

Hi,

 

I hope someone is able to help me with this:

 

I have a table with data from different batch dates and would like to compare the planned date versus the actual date at different batch dates.

 

ID

Batch Date

Actual Date

Planned Date

123214

04.05.2018

 

07.07.2018

43344

04.05.2018

 

08.07.2018

4545

04.05.2018

 

09.07.2018

123214

06.05.2018

 

11.07.2018

43344

06.05.2018

05.07.2018

 

4545

06.05.2018

03.07.2018

 

123214

07.05.2018

06.07.2018

 

43344

07.05.2018

05.07.2018

 

4545

07.05.2018

03.07.2018

 

 

For Example:

Planned date at Batch date 04.05. compared with Actual date at Batch date 07.05.:

 

 

Planned at 04.05.Batch Date

Actual at 07.05.Batch

Days difference

123214

07.07.2018

06.07.2018

-1

43344

08.07.2018

05.07.2018

-3

4545

09.07.2018

03.07.2018

-6

Total

 

 

-10

 

 

I have tried using two different date tables (Previous and Current Date) that have an inactive connection to the batch date column but I can’t create correct measures for calculating the “days difference”.

 

 
2 REPLIES 2
ChrisMendoza
Resident Rockstar
Resident Rockstar

Hello @chrismpbi,

 

I decided to make a go at this. Hopefully it will get you close(r) to your desired result.

 

Using your sample dataset 'Table1' in DAX:

 

Create a new table:

tblActual = 
SUMMARIZECOLUMNS(Table1[ID],Table1[Actual Date],LASTDATE(Table1[Batch Date]))

Create another table:

tblPlanned = 
SUMMARIZECOLUMNS(Table1[ID],Table1[Planned Date],FIRSTDATE(Table1[Batch Date]))

In 'tblPlanned' add column:

Actual at 07.05.Batch = LOOKUPVALUE('tblActual'[Actual Date],'tblActual'[ID],'tblPlanned'[ID])

In 'tblPlanned' add another column for [Days difference]:

Days difference = 'tblPlanned'[Actual at 07.05.Batch].[Day]-'tblPlanned'[Planned Date 04.05.Batch Date].[Day]

This should yield:

1.PNG

 

I honestly don't know how how this will work with additional data rows however, it seems to work for the small sample dataset.

 

Possibly there is a better solution to handling this?






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Hi ChrisMendoza,

 

thank you very much for your response. I think as you mentioned this solution would work for this example data set. But my real dataset is much bigger with hundreds of "Batch Dates".

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.