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

New Table: IF x is true, then CALCULATETABLE a, else CALCULATETABLE b

Hey all,

I've got what I thought would be a straightforward DAX expression, but it's apparently not... I want it to evaluate today's date, and if today is before November 1, then calculate a table with certain filters applied, otherwise apply different filters. Independently, each version of the CALCUALTETABLE works; it's just when I roll it into the IF statement that it errors. I will probably just have to figure out a different way to achieve the model I'm looking for, but on the off chance I'm missing something simple, have a look. The error I'm getting is, "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

New Table =

if(today()=date(year(today()),11,1),

CALCULATETABLE(
'Sales Order',
'Sales Order'[OrderApi__Date__c]>= DATE(2017,11,9),
'Sales Order'[OrderApi__Date__c]<= DATE(2018,10,31))
,

CALCULATETABLE(
'Sales Order',
'Sales Order'[OrderApi__Date__c]>= DATE(2017,11,9),
'Sales Order'[OrderApi__Date__c]<= DATE(2018,month(today()),day(today()))
)
)

Thanks for the help!

 

1 REPLY 1
Greg_Deckler
Super User
Super User

That's actually kind of weird. But, you can solve it like this:

 

New Table =

VAR filter1 = DATE(2017,11,9)
VAR filter2a = DATE(2018,10,31)
VAR filter2b = DATE(2018,month(today()),day(today()))
VAR filter2 = if(today()<date(year(today()),11,1),filter2a,filter2b)

RETURN 

CALCULATETABLE(
'Sales Order',
'Sales Order'[OrderApi__Date__c]>= filter1,
'Sales Order'[OrderApi__Date__c]<= filter2)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.