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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

DAX for group by and datediff

Hi 

 

i have a table with 2 columns

 

 

id   start_date 

 

1     2017/05/06

2       ""

3       ""

4        ""

1    2018/06/05

1       ""

2        ""

 

Now I want to add a new column here which shows

a. The difference in start_date vs today ( I am able to achieve this using datediff function) 

b. I want to apply group by to 'id' column and take the latest date in the start_date column. In the above example for id=1 and start_date = 2018/06/05.  Once I am able to group by id and get the latest start_date for that id then I would find diff of it with today's date. 

 

Please help 

 

 

1 ACCEPTED SOLUTION
v-danhe-msft
Employee
Employee

Hi @Anonymous,

Based on my test, you could refer to below formula:

Difference column:

Difference = DATEDIFF('Table1'[start_date],TODAY(),DAY)

1.PNG

Group by table:

Group by table = SUMMARIZE('Table1','Table1'[id],"Latest",CALCULATE(MAX('Table1'[start_date])))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
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

3 REPLIES 3
CylesteGranite
New Member

I have a similar issue, but still struggling with the solution provided.  I am trying to add a DATEDIFF column to a table visual with an aggregate column (count of tickets).  The DATEDIFF calc works if I exclude the # of Tickets aggregate column.  

DaysLate = DATEDIFF(Tkscale[TicketDate], Today(),DAY)
 
This is what I expect to see:
TicketDate# of TicketsDaysLate
02/25/2031
02/25/20141
02/25/20621

 

This is what I currently see:

TicketDate# of TicketsDaysLate
02/25/2033
02/25/201414
02/25/206262
   

What should the calculation look like?

 

Thank you,

Cyleste

v-danhe-msft
Employee
Employee

Hi @Anonymous ,

Could you please tell me if your problem has been solved? If it is, could you please mark the helpful replies as Answered to close this topic?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-danhe-msft
Employee
Employee

Hi @Anonymous,

Based on my test, you could refer to below formula:

Difference column:

Difference = DATEDIFF('Table1'[start_date],TODAY(),DAY)

1.PNG

Group by table:

Group by table = SUMMARIZE('Table1','Table1'[id],"Latest",CALCULATE(MAX('Table1'[start_date])))

Result:

1.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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