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
Anonymous
Not applicable

CALCULATE measure with date filter

Hello! 

My data set: 

'Date'[Date] - Default data table, used as report filter 

 

Table:

Product_IDDate_Start...
243220.02.2022 
352221.02.2022 
...... 

 

Task: Count number of distinct Product which started at given date

 

MEASURE1 = CALCULATE(DISTINCTCOUNT(Table[Product_ID]), Table[Date_Start] = MAX('Date'[Date]))
gives empty result for any date
but
MEASURE2= CALCULATE(DISTINCTCOUNT(Table[Product_ID]), Table[Date_Start] = MAX('Date'[Date])-1)
gives good result for any date, but its moved by one day 
 
I tried using solution which i found here on forum wich is: 
MEASURE3= CALCULATE(DISTINCTCOUNT(Table[Product_ID]), FILTER(Table, Table[Date_Start] = MAX('Date'[Date])))
but result is still empty

No error reported in PBI
 
I want to use relative date in raport to present number of products for yesterday, today and tommorow, so i need it to work without this (-1) element. It seems to bo so simple measure, but it gave me headache.
 
2 ACCEPTED SOLUTIONS
Jos_Woolley
Solution Sage
Solution Sage

Sounds like the entries in 'Date'[Date] aren't formatted as proper dates. Hence the conversion to a correct date by a simple mathematical operation (for example, your subtraction of 1).

Regards

View solution in original post

Anonymous
Not applicable

Ok, so everything looked fine at first glance. 
But changing date table from defined in report by:

Date = CALENDAR(DATE(1990, 01,01),DATE(2099,12,31))

to Data table generated in power query solved the issue.

Thanks for guidance. 

View solution in original post

5 REPLIES 5
Jos_Woolley
Solution Sage
Solution Sage

Sounds like the entries in 'Date'[Date] aren't formatted as proper dates. Hence the conversion to a correct date by a simple mathematical operation (for example, your subtraction of 1).

Regards

Anonymous
Not applicable

Ok, so everything looked fine at first glance. 
But changing date table from defined in report by:

Date = CALENDAR(DATE(1990, 01,01),DATE(2099,12,31))

to Data table generated in power query solved the issue.

Thanks for guidance. 

Anonymous
Not applicable

Date = CALENDAR(DATE(1990, 01,01),DATE(2099,12,31))


and column: 'Date'[Date], data type is "Date"

Jos_Woolley
Solution Sage
Solution Sage

Hi,

MyMeasure :=
VAR ThisDate =
    MAX( 'Date'[Date] )
RETURN
    CALCULATE(
        DISTINCTCOUNT( 'Table'[Product_ID] ),
        'Table'[Date_Start] = ThisDate
    )

which is identical to:

MyMeasure :=
VAR ThisDate =
    MAX( 'Date'[Date] )
RETURN
    CALCULATE(
        DISTINCTCOUNT( 'Table'[Product_ID] ),
        FILTER(
            ALL( 'Table' ),
            'Table'[Date_Start] = ThisDate
        )
    )

Regards

Anonymous
Not applicable

I have already tried this alternative , no change. As in my post, it works with 

 ThisDate =
    MAX( 'Date'[Date] ) - 1

 

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.

Top Solution Authors