cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
gladies123
Helper I
Helper I

Reg: Adding Dates

Hi Team,

This is to inform you that i am having different two date one is refresh date another one is id_expiry date, if i select a date from slicer which contains refresh_date for example date is (29-06-2021) that id_expiry date should return from (01-06-2021 to 30-6-2021)=this month, and (01-07-2021 to 31-07-2021)=next month, (01-06-2021 to 31-07-2021)=60 days and (01-06-2021 to 31-08-2021)=90 days . Kindly help me on this dax.

 

Thanks,

Gladis

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @gladies123 ,

 

First create a calendar table as the slicer;

Then create 4 measures as below:

id_expiry date(this month) =
VAR _startdate =
    STARTOFMONTH ( 'Table 2'[Date] )
VAR _enddate =
    ENDOFMONTH ( 'Table 2'[Date] )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )
id_expiry date(next month) =
VAR _startdate =
    DATEADD ( STARTOFMONTH ( 'Table 2'[Date] ), 1, MONTH )
VAR _enddate =
    DATEADD ( ENDOFMONTH ( 'Table 2'[Date] ), 1, MONTH )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )
id_expiry date(60 days) =
VAR _startdate =
    STARTOFMONTH ( 'Table 2'[Date] )
VAR _enddate =
    DATEADD ( ENDOFMONTH ( 'Table 2'[Date] ), 1, MONTH )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )
id_expiry date(90 days) =
VAR _startdate =
    STARTOFMONTH ( 'Table 2'[Date] )
VAR _enddate =
    DATEADD ( ENDOFMONTH ( 'Table 2'[Date] ), 2, MONTH )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )

And you will see:

vkellymsft_0-1630915364845.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

View solution in original post

2 REPLIES 2
v-kelly-msft
Community Support
Community Support

Hi @gladies123 ,

 

First create a calendar table as the slicer;

Then create 4 measures as below:

id_expiry date(this month) =
VAR _startdate =
    STARTOFMONTH ( 'Table 2'[Date] )
VAR _enddate =
    ENDOFMONTH ( 'Table 2'[Date] )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )
id_expiry date(next month) =
VAR _startdate =
    DATEADD ( STARTOFMONTH ( 'Table 2'[Date] ), 1, MONTH )
VAR _enddate =
    DATEADD ( ENDOFMONTH ( 'Table 2'[Date] ), 1, MONTH )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )
id_expiry date(60 days) =
VAR _startdate =
    STARTOFMONTH ( 'Table 2'[Date] )
VAR _enddate =
    DATEADD ( ENDOFMONTH ( 'Table 2'[Date] ), 1, MONTH )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )
id_expiry date(90 days) =
VAR _startdate =
    STARTOFMONTH ( 'Table 2'[Date] )
VAR _enddate =
    DATEADD ( ENDOFMONTH ( 'Table 2'[Date] ), 2, MONTH )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 2'[Date] ) IN FILTERS ( 'Table'[refresh date] ),
        FORMAT ( _startdate, "dd-mm-yyyy" ) & " to "
            & FORMAT ( _enddate, "dd-mm-yyyy" )
    )

And you will see:

vkellymsft_0-1630915364845.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

View solution in original post

amitchandak
Super User
Super User

@gladies123 ,The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin

Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
Proud to be a Super User!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

November Power BI Update 768x460.png

Check it Out!

Click here to read more about the November 2021 Updates!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.