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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
ManeeshaY_12345
New Member

Time inteligence DAX

Hi  I have repeted part numbers with different date, need to create a new column by using dax, that having days numbers, difference between current date and earlier date. if part number is recording for the forst time days should be 0, and for next record  days would be difference between 2nd record date and 1st record date .

IDDateNo Of Days
R12323/09/20230
R12322/10/202330
R12301/11/202311
R23429/09/20230
R23412/10/202314
R23423/11/202351
6 REPLIES 6
Musadev
Resolver III
Resolver III

Hi @ManeeshaY_12345 
Please check the steps for your data and update if you are getting the desired results.
Step 1: Here is my custom dataset.

Musadev_0-1708963957904.png

Step 2: I have created a Calculated Column to rank All the products based on the date.

Date Rank =
RANKX (
    FILTER(ALLSELECTED(TI), TI[ID] = EARLIER(TI[ID])),  -- Filter rows for the same ID
    TI[DATE],
    ,
    ASC  -- Sort dates in Ascending order
)
Step 3: Calculate the number of days for each record in the below Calculated column.
# of Days =
VAR MinDate =
    CALCULATE(
        MIN(TI[DATE]),
        FILTER(ALLSELECTED(TI), TI[ID] = EARLIER(TI[ID]))
    )
RETURN
    IF(
        TI[DATE] = MinDate,
        0,  -- Set rank 1 as 0
        DATEDIFF(MinDate, TI[DATE], DAY)  -- Calculate difference in days
    )

Here is the output for my data.
Musadev_1-1708964355845.png

 

Musadev
Resolver III
Resolver III

You will have multiple dates for a single ID right?
right now you have only 3 but in future, it will have multiples

Yes, In future new records will add for same ID.

@ManeeshaY_12345 , We can use offset function to get that

 

Last row = CALCULATE(Sum(Table[Numer of Days]) , OFFSET(-1, ALLSELECTED('Table'[ID],'Table'[DAte]), ORDERBY('Table'[Date],asc),KEEP,PARTITIONBY('Table'[ID])))+0

 

Continue to explore Power BI Offset Compare Categories, Time Intelligence MOM, QOQ, and YOY: https://youtu.be/5YMlkDNGr0U

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks @amitchandak  for sharing above logic,
but I want to confirm you that I am expecting to create NO of days column. as of now I dont have that column in my table for understanding i just mentioned there.
Sorry for unclear information.

@ManeeshaY_12345 , My Mistake ,Please try

 

Last row =
var _last =CALCULATE(Max(Table[Date]) , OFFSET(-1, ALLSELECTED('Table'[ID],'Table'[DAte]), ORDERBY('Table'[Date],asc),KEEP,PARTITIONBY('Table'[ID]))), Max('Table'[Date])
return
if(isblank(_last), 0, Datediff(_last, Max('Table'[Date]) , day))

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors