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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Kumar11109
Helper IV
Helper IV

Days Gap For Each Group

Hi All, 

 

I want to find the gap between dates for each group. Sample data can be found here. 

 

Data

 

How will be able to do it. 

 

Thank You, 

 

1 ACCEPTED SOLUTION

Hi,

 

This is the calculated column formula i wrote.  You may download my solution file from here.

 

=if(ISBLANK(CALCULATE(MAX(Data[Session Date]),FILTER(Data,Data[GroupId]=EARLIER(Data[GroupId])&&Data[Session Date]<EARLIER(Data[Session Date])))),BLANK(),Data[Session Date]-CALCULATE(MAX(Data[Session Date]),FILTER(Data,Data[GroupId]=EARLIER(Data[GroupId])&&Data[Session Date]<EARLIER(Data[Session Date]))))

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

 

Show the result in a simple Table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur, Do you mean the required result?  If yes, its already in the  sample data set. Remember this is just for three groups. Actual data size is much bigger. 

 

 

Hi,

 

This is the calculated column formula i wrote.  You may download my solution file from here.

 

=if(ISBLANK(CALCULATE(MAX(Data[Session Date]),FILTER(Data,Data[GroupId]=EARLIER(Data[GroupId])&&Data[Session Date]<EARLIER(Data[Session Date])))),BLANK(),Data[Session Date]-CALCULATE(MAX(Data[Session Date]),FILTER(Data,Data[GroupId]=EARLIER(Data[GroupId])&&Data[Session Date]<EARLIER(Data[Session Date]))))

 

Hope this helps.

 

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Tried this way,

  1. Create a new column named Rank,

Rank =
VAR d=Table1[Session Date].[Date]
VAR c=Table1[GroupId]
RETURN
CALCULATE(RANK.EQ(d,Table1[Session Date].[Date],ASC),FILTER(ALL(Table1),Table1[GroupId]=c))

 

2. Create a new column named DateDiff,

DateDiff =
VAR d=Table1[Session Date].[Date]
VAR r=Table1[Rank]
VAR g=Table1[GroupId]
RETURN
CALCULATE(DATEDIFF(LOOKUPVALUE(Table1[Session Date],Table1[GroupId],g,Table1[Rank],r-1),d,DAY))

 

Anonymous
Not applicable

Hi @Kumar11109,

 

Do you wish to calculate days between Latest and Earliest  Session Date for each group?

No I want to calculate difference between each date for each group. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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