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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Help with Date filtering on measure

I have a table that has contract data and I need to show Contract YTD info. Here is an example:

 

Contract1 active dates 1/1/2018 - 12/31/2018

Contract2 active dates  4/1/2018 - 5/31/2019

Contract3 active dates  5/1/2018 - 12/31/2018

 

My data is setup so that contract2 would look like this:

 

Date...........Contract...........Amount.............Active
4/1/2018.......contract2.........500....................1
5/1/2018.......contract2.........600....................1
6/1/2018.......contract2.........900....................1
7/1/2018.......contract2.........500....................1
8/1/2018.......contract2.........500....................1
9/1/2018.......contract2.........400....................1
10/1/2018.....contract2.........500....................1
11/1/2018.....contract2.........500....................1
12/1/2018.....contract2.........200....................1
1/1/2019.......contract2.........500....................1
2/1/2019.......contract2.........900....................1
3/1/2019.......contract2.........500....................1
4/1/2019.......contract2.........200....................1
5/1/2019.......contract2.........100....................1

I have another regular daily transaction table (factSales) that is tracking Quantity.

 

What I need to do is figure out the DAX to get the total Quantity for only the contract YTD. Below is true YTD. I need to alter this so that the starting date will always be the first Contract Date for the respective contract. So, I'd want contract1 to start on 1/1/2018, Contract2 to start 4/1/2018, and contract3 to start 5/1/2018. I already have other filtering so it will only return Active contracts. My issue is with limiting the Quantity from Sales to stay within the contract date bounds.

 

YTDTotalInvoiced = CALCULATE(SUM(factSales[Quantity]),filter('Date','Date'[Date]<=today()-1 && 'Date'[Date]>=DATE(YEAR(TODAY()-1),1,1)))
1 ACCEPTED SOLUTION
Anonymous
Not applicable

It was not solved in Power BI. I had to change my fact table to include the Sales Quantity to get it to work as desired. Not ideal.

View solution in original post

4 REPLIES 4
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

Could you tell me if your problem has been solved? If it is,kindly mark the helpful answer as a solution and welcome to share your own solution. More people will benefit from here. If not, please share more details for us so that we could help further on it.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

It was not solved in Power BI. I had to change my fact table to include the Sales Quantity to get it to work as desired. Not ideal.

Anonymous
Not applicable

Try this.

 

TOTALYTD(SUM(factSales[Quantity]),'Calendar'[Date],ALL(factSales),"5/31/2019") - for Contract 2.

Use the same for Contract 1 and 3 (change the year end date), it will work.

Please let me know if you have any questions.

 

Regards,

Pavan Vanguri.

 

 

v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

Please check if below measure could help you.

Measure  =
CALCULATE (
    SUM ( factSales[Amount] ),
    FILTER (
        ALL ( factSales ),
        factSales[Date] >= MAX ( Contract[active dates] )
            && factSales[Date] <= MAX ( Contract[end dates] )
    )
)

Regards,

Cherie

 

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.