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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Raul
Post Patron
Post Patron

DAX Formula for a date field

Hello Community!

 

I have the Calendar table related to the Table1 table by the field Calendar[Date] - Table1[Date] and related to the Table2 table by the field Calendar[Date] - Table2[Date].

I need a mesure to calculate the sum of values of the Amount field according to this condition:

  • The amounts of the records in Table 1 for the period 01/01/selected year to 03/31/selected year plus the records in Table 2 for the period 09/01/selected year+1 to 12/31/selected year+1

 

And I create this measure:

Measure = 

VAR varYear = SELECTEDVALUE(Calendar[Year])
RETURN
CALCULATE(SUM(Table2[Amount]), ALL(Calendar), DATESBETWEEN(Table2[Date], DATE(varYear+1,09,01), DATE(varYear+1,12,31))) +
CALCULATE(SUM(Table1[Amount]), DATESBETWEEN(Table1[Date], DATE(varYear,01,01), DATE(varYear,03,31)))

 

But the measurement results are not correct because it returns records that do not match the condition I need. What is wrong with the DAX formula?

Thank you.

1 ACCEPTED SOLUTION

Of course:

Measure = 

   VAR varYear = SELECTEDVALUE(Calendar[Year])
   VAR varPVY = CALCULATE(SUM(Table2[Amount]), ALL(Calendar), DATESBETWEEN(Table2[Date], DATE(varYear+1,09,01), DATE(varYear+1,12,31)))
   VAR varACY = CALCULATE(SUM(Table1[Amount]), ALL(Calendar), DATESBETWEEN(Table1[Date], DATE(varYear,01,01), DATE(varYear,03,31)))
RETURN
   varPVY + varACY
 
 

View solution in original post

8 REPLIES 8
Raul
Post Patron
Post Patron

Hi @amitchandak,

Thank you for your comment but the result it's the same as with my formula. Any other suggestions?

Hi @Raul,

Can you please share some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
v-shex-msft
Community Support
Community Support

HI @Raul,

Did amitchandak 's suggestion help with your scenario? if that is the case, you can consider Kudo or accept his suggestions to help others who faced similar requirements find it more quickly.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

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

@Raul , Try like

 


Measure =
VAR varYear = SELECTEDVALUE(Calendar[Year])
RETURN
CALCULATE(SUM(Table2[Amount]), filter(Table2, Table2[Date]>= DATE(varYear+1,09,01) && Table2[Date]<= DATE(varYear+1,12,31))) +
CALCULATE(SUM(Table1[Amount]), filter(Table1,Table1[Date] >= DATE(varYear,01,01) && Table1[Date] <= DATE(varYear,03,31)))

 

or


Measure =
VAR varYear = SELECTEDVALUE(Calendar[Year])
RETURN
CALCULATE(SUM(Table2[Amount]), filter(Table2, Table2[Date]>= DATE(varYear+1,09,01) && Table2[Date]<= DATE(varYear+1,12,31)), all(calendar)) +
CALCULATE(SUM(Table1[Amount]), filter(Table1,Table1[Date] >= DATE(varYear,01,01) && Table1[Date] <= DATE(varYear,03,31)), all(calendar))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak and @v-shex-msft 

I solved my question by creating a variable for each option and sum both variables.
Thank you for your help.

Hi @amitchandak and @v-shex-msft 

I solved my question by creating a variable for each option and sum both variables.
Thank you for your help.

Hi @Raul,

I'm glad to hear you find the solution.😊

BTW, did you mind sharing a sample formula for this? I think it will help other users who were looking for a similar formula.

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Of course:

Measure = 

   VAR varYear = SELECTEDVALUE(Calendar[Year])
   VAR varPVY = CALCULATE(SUM(Table2[Amount]), ALL(Calendar), DATESBETWEEN(Table2[Date], DATE(varYear+1,09,01), DATE(varYear+1,12,31)))
   VAR varACY = CALCULATE(SUM(Table1[Amount]), ALL(Calendar), DATESBETWEEN(Table1[Date], DATE(varYear,01,01), DATE(varYear,03,31)))
RETURN
   varPVY + varACY
 
 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.