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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mrawat7
Frequent Visitor

Create a calculate column based on date

Hello,

 

I am trying to create a calculated column based on a user selected date.

 

I have a table containing membership data.  The table includes a column for StartDate (start of membership) and another for ExpiryDate (end of membership).

 

So if the user selects a date (e.g. 01/08/2022) the column would return '1' if the selected date is between StartDate and ExpiryDate, or '0' if it is not.

 

In SQL it would look like this:

 

CASE 

 WHEN @EndDate
   BETWEEN StartDate AND ExpiryDate THEN 

     1

   ELSE

     0
END

 

Can this be done in PowerQuery or DAX

 

Thanks in avanced!

 

M

 

1 ACCEPTED SOLUTION

I think I have figured it out:

 

Measure = 
VAR __SelectedDate =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
         distinctcount(memberships[contactid]), memberships[startdate].[Date] <= __SelectedDate, __SelectedDate <= memberships[expirydate].[Date]
    )

View solution in original post

4 REPLIES 4
mrawat7
Frequent Visitor

Thanks @Adescrit,

 

That was really helpful and appreciated!

 

It works to a certain degree with my dataset.  

 

The Membership table has a many-to-one relationship with the Customer table, as there are scenarios where customer can have more than one membership, and I want to eliminate the possiblity of double counting Members.

 

Instead of the conditional statement returning 1, would it be possible to return CustomerID then Distinctcount CustomerID?

 

Kind regards,

 

M

I think I have figured it out:

 

Measure = 
VAR __SelectedDate =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
         distinctcount(memberships[contactid]), memberships[startdate].[Date] <= __SelectedDate, __SelectedDate <= memberships[expirydate].[Date]
    )
Adescrit
Impactful Individual
Impactful Individual

Excellent! Yes that looks good.


Did I answer your question? Mark my post as a solution!
My LinkedIn
Adescrit
Impactful Individual
Impactful Individual

Hi @mrawat7 ,

 

As far as I know it is not possible to pass a selected slicer value to a calculated column.

 

You could use a measure though. Are you trying to calculate the number of members active on the selected date? If so you could use a formula like this:

 

 

Between =
VAR __SelectedDate =
    SELECTEDVALUE ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUMX (
            Members,
            IF ( Members[StartDate] <= __SelectedDate && __SelectedDate <= Members[ExpiryDate], 1, 0 )
        ),
        ALL ( 'Date'[Date] )
    )

 

 

In this scenario we have a Date dimension table containing a list of dates, and Members is the table containing membership data.


Did I answer your question? Mark my post as a solution!
My LinkedIn

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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