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

Filter by datediff in Analysis Services

Hello, 
I have created a calculation 

Measure = CALCULATE(
                    DISTINCTCOUNT([Supplier Name]),
                        DATEDIFF(max([Creation Date]),
                                      TODAY(),year)==1
)

 

with the hope that I will get the the suppliers that were created last year etc. 
Unfortunately i am working on analysis services so it does pop an error :A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed. 
Unfortunately i can make no tables or go back to the model itself. 
Any ideas?

1 ACCEPTED SOLUTION

@Anonymous , Try like

Measure = CALCULATE(
COUNTX(values(Table[Supplier Name]),table[Supplier Name]),
filter(table, DATEDIFF(max([Creation Date]),
TODAY(),year)=1
))

OR

Measure = countx(summarize(Table , Table[Supplier Name], "_1",
calculate(lDISTINCTCOUNT([Supplier Name]),
filter(table, DATEDIFF(max([Creation Date]),
TODAY(),year)=1
))),[_1])

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , try like

Measure = CALCULATE(
DISTINCTCOUNT([Supplier Name]),
filter(table, DATEDIFF(max([Creation Date]),
TODAY(),year)=1
))

Anonymous
Not applicable

Seems like a plausible solution @amitchandak but this is what I got when I tried to use itUntitled.png

SO it works only when I have the field of suppliers in the view, not in the card, isn't it strange?

@Anonymous , Try like

Measure = CALCULATE(
COUNTX(values(Table[Supplier Name]),table[Supplier Name]),
filter(table, DATEDIFF(max([Creation Date]),
TODAY(),year)=1
))

OR

Measure = countx(summarize(Table , Table[Supplier Name], "_1",
calculate(lDISTINCTCOUNT([Supplier Name]),
filter(table, DATEDIFF(max([Creation Date]),
TODAY(),year)=1
))),[_1])

Anonymous
Not applicable

Thanks! I was thinking of an addition of an "or" operator something like

Measure = countx(summarize(Table , Table[Supplier Name], "_1",
calculate(lDISTINCTCOUNT([Supplier Name]),or(
filter(table, DATEDIFF(max([Creation Date]),
TODAY(),year)=1),max([Creation Date]=Blank())
))),[_1])

but it doesn't seem that or works in analysis services that way, so I have solved this issue with creating and adding the different measures. Any better idea on this @amitchandak ?
Thanks again!

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.