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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
EUGENEG
Helper I
Helper I

Using date selected in a calculated column

Good day 

 

I currently have a situation were I am required to allow a report to filter via a date selection ie:The OrderDate

I have a calculated column that uses the "datediff" and "today" functions however I want to subsitute the "Today" function with the date selected on the date filter 

 

Calculated Column as below 

Sales = IF(DATEDIFF(SALES[ORDERDATE].[Date],TODAY(),DAY)>=30
&& (DATEDIFF(SALES[ORDERDATE].[Date],TODAY(),DAY)<60),CALCULATE(COUNT(SALES[ORDERREFERENCE])))

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

hi @EUGENEG 

First, you should know that:

1. Calculation column/table not support dynamic changed based on filter or slicer.
2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

Second, for your case, you could use a measure as below:

Sales =
IF (
    DATEDIFF ( MAX(SALES[ORDERDATE].[Date]), MAX(Date[Date]), DAY ) >= 30
        && ( MAX(DATEDIFF ( SALES[ORDERDATE].[Date]), MAX(Date[Date]), DAY ) < 60 ),
    CALCULATE ( COUNT ( SALES[ORDERREFERENCE] ) )
)

 

Date[Date] is a slicer

Then drag all fields from SALES table and this measure [Sales] into a table visual.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-lili6-msft
Community Support
Community Support

hi @EUGENEG 

First, you should know that:

1. Calculation column/table not support dynamic changed based on filter or slicer.
2. Measure can be affected by filter/slicer, so you can use it to get dynamic summary

https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/

Second, for your case, you could use a measure as below:

Sales =
IF (
    DATEDIFF ( MAX(SALES[ORDERDATE].[Date]), MAX(Date[Date]), DAY ) >= 30
        && ( MAX(DATEDIFF ( SALES[ORDERDATE].[Date]), MAX(Date[Date]), DAY ) < 60 ),
    CALCULATE ( COUNT ( SALES[ORDERREFERENCE] ) )
)

 

Date[Date] is a slicer

Then drag all fields from SALES table and this measure [Sales] into a table visual.

 

Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

I doubt column But Measure can be

Measure = 
var _max = maxx('Calendar',('Calendar'[Date]))
return
DATEDIFF(FIRSTNONBLANK(salesorder[DATE],TRUE()),_max,MONTH)

 

 

Anonymous
Not applicable

Calculated columns can not be dynamic, they are getting loaded when you are loading your dataset for first time.

 

You can try measure 

 I recommend you to create one dummy calendar date table which is not connected with any other table in your model.

 

Use 'calendar date'[Date] column in slicer and make it your slicer as after slicer or between slicer.

 

then update your sales measure by replacing today() with min('calendar date'[Date])

 

Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar

If I resolve your problem Mark it as a solution and give kudos.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.