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
CharlesMS
Frequent Visitor

Calculating current Quarter and use filter in DAX

So i have this DAX here and I want to be selecting current Quarter automatically instead of manually changing it every time what should I change?

 

Target = Calculate(SUM('TABLE'[Budget])/12, FILTER( TABLE,'TABLE'[Year]=2018 && 'TABLE'[Quarter]="Q3"))
 
Can I also do this with year too? in a different query.
Or use a function to calcualte QTD?
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@CharlesMS Try:

Target = 
  VAR __Quarter = "Q" & QUARTER(TODAY())
  VAR __Result = 
Calculate(SUM('TABLE'[Budget])/12, FILTER( TABLE,'TABLE'[Year]=2018 && 'TABLE'[Quarter]=__Quarter))
RETURN
  __Result


@ 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...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@CharlesMS Try:

Target = 
  VAR __Quarter = "Q" & QUARTER(TODAY())
  VAR __Result = 
Calculate(SUM('TABLE'[Budget])/12, FILTER( TABLE,'TABLE'[Year]=2018 && 'TABLE'[Quarter]=__Quarter))
RETURN
  __Result


@ 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...

@Greg_Deckler 

I get the following error when I use this now:

MdxScript(Model) (1427,67) Calculation error in measure 'Table'[Measure]: DAX comparison operations do not support comparing value of type Text with value of type integer.

Consider using the Value or format function to convert one of the values.

 

 

 

So my measure is :

Measure =
VAR __Current_year = Year(Now())
VAR __Quarter = "Q" & QUARTER(TODAY())
  VAR __Result =
Calculate(SUM('Table'[cost]), FILTER( 'Table','Table'[Year] = __Current_year && 'Table'[Quarter]=__Quarter && 'Table'[activity_type]= "X"))
RETURN
  __Result

 

The column Year is dax like this:

Year = FORMAT('Table'[date],"yyyy")
 
The column Quarter is dax like this:
Quarter = FORMAT('Table'[date],"q")
 
and the date is a measure i have in my Table like this format:
25/12/2022
 
But apparently my Quarter and Year columns are formatted as Text and Can't compare them with numbers , how do I change them ?
When I view the table I can't see those columns

 

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