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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
SebaSpotti
Regular Visitor

Create a Column with a Measure as Dates comparision

Hi! 

I created a Measure in this way, by getting the values of Date after selecting it in a Slicer:

SelectedDate = SELECTEDVALUE('Date'[Date])
 
then i want to create a column the told me if the "SelectedDate" is between two given dates, ad I use this:
Data1 = IF(AND('Table'[StartDate]<='Table'[SelectedDate],'Table'[EndDate]>='Table'[SelectedDate]),1,0)
 
but i get only 0, even if there are some cases in which the formula must give back1.
I checked that all dates are in the same format.
 
Any suggestions?
Thanks!
1 ACCEPTED SOLUTION
Gabry
Responsive Resident
Responsive Resident

Yes this should be good if put on a measure. Doesn't work?

well not properly as you wrote
this should work:
Measure =  VAR DataControllo = SELECTEDVALUE ( 'Date'[Date] )

 
  
    RETURN
       CALCULATE ( SUM ( Table[Cost] ),
    Table[StartDate] <= DataControllo,
    Table[EndDate] >= DataControllo
)

Sei italiano?

View solution in original post

4 REPLIES 4
Gabry
Responsive Resident
Responsive Resident

As i know you can't create calculated column based on a measure value that is evaluated on the fly.


You should use a measure and not a calculated column. Calculated columns are evaluated only when you refresh the data

So also this solution is not ok?

 

SumData1 =
CALCULATE (
    VAR DataControllo = SELECTEDVALUE ( 'Date'[Date] )
    RETURN
        SUM ( Table[Cost] ),
    Table[StartDate] <= DataControllo,
    Table[EndDate] >= DataControllo
)
 
Thanks
Gabry
Responsive Resident
Responsive Resident

Yes this should be good if put on a measure. Doesn't work?

well not properly as you wrote
this should work:
Measure =  VAR DataControllo = SELECTEDVALUE ( 'Date'[Date] )

 
  
    RETURN
       CALCULATE ( SUM ( Table[Cost] ),
    Table[StartDate] <= DataControllo,
    Table[EndDate] >= DataControllo
)

Sei italiano?

si sono italiano 😁

 

giusto, così "funziona"..le somme che mi restituisce mi sembrano sbagliate ma devo ricontrollare la condizione probabilmente..

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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