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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
manideep547
Helper III
Helper III

how to get the date difference

Date difference between the current date(selected values(table  A[date])) and previous date with if condition like 
if(datediff(selectedvalues(tableA[date]),earlier(tableA[date]),month,"S","L") in measure 

 

1 ACCEPTED SOLUTION

Hi,

 

I create a table to test:

131.PNG

Then create a calculated date table:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Create two measures:

Measure = DATEDIFF(MIN('Table'[Date]),MIN('Date'[Date]),MONTH)
Measure 2 = DATEDIFF(MAX('Table'[Date]),MAX('Date'[Date]),MONTH)

And then continue to create a measure to show each ID's status:

Status = IF([Measure]>0||[Measure 2]>0,SWITCH(true,([Measure]>=0&&[Measure]<6)||([Measure 2]>=0&&[Measure 2]<6),"S",[Measure]>=6||[Measure 2]>=6,"L"),"N")

The result shows:

132.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

View solution in original post

3 REPLIES 3
v-gizhi-msft
Community Support
Community Support

Hi,

 

I am confused about how you define the previous date.

If you want to get the difference between previous one month date and current date(today), please try this measure:

 

Measure =
IF (
    DATEDIFF (
        SELECTEDVALUE ( 'Table'[Date] ),
        IF (
            MONTH ( TODAY () ) = 1,
            DATE ( YEAR ( TODAY () ) - 1, 12, DAY ( TODAY () ) ),
            DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) )
        ),
        MONTH
    ),
    "S",
    "L"
)

 

And it shows:

101.PNG

Hope this helps.

 

Best Regards,

Giotto Zhi

@v-gizhi-msft 
ID   DATE  (DD/MM/YYYY)
1     02/08/2017
3     02/01/2017

1       02/01/2018
2       08/12/2018
3      09/12/2018


 
If the customer not having any transaction in the past considered as an N
if the customer having a transaction in the selected period in the slicer  and also having a transaction in past within the 6 months period then considers as S
if the customer having  a transaction in the selected period in the slicer  and also having a transaction in the past +6months period then considers as L

 

IN slicer I selected the date from 1/1/2018 to 1/12/2018 then

Here date different I want is for ID '1 '  consider as an A
for Id' 2' consider as an N and Id 3 considers as L


Thanks & regards 
CH Mani deep

 

Hi,

 

I create a table to test:

131.PNG

Then create a calculated date table:

Date = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Create two measures:

Measure = DATEDIFF(MIN('Table'[Date]),MIN('Date'[Date]),MONTH)
Measure 2 = DATEDIFF(MAX('Table'[Date]),MAX('Date'[Date]),MONTH)

And then continue to create a measure to show each ID's status:

Status = IF([Measure]>0||[Measure 2]>0,SWITCH(true,([Measure]>=0&&[Measure]<6)||([Measure 2]>=0&&[Measure 2]<6),"S",[Measure]>=6||[Measure 2]>=6,"L"),"N")

The result shows:

132.PNG

Here is my test pbix file:

pbix 

Hope this helps.

 

Best Regards,

Giotto Zhi

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors