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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
FarihaImami
Frequent Visitor

Calculate total between two dates while ignoring date date selection

Hi. 

 

I hope I can explain my issue well. Maybe I am overthining this.

 

I have a report where user can select Year, Month, Week individually. I have a table with total production/runtime and other information. I want to add Average daily production YTD on this table based on ONLY selected year or years. Basic formula for this: 

 

Average daily production YTD = total production for selected / number of days selected

 

Number Of Days Selected= DATEDIFF(FIRSTDATE('datetable'[StartOfYear]), LASTDATE('datetable'[endofyear]),DAY)+1

 

The solution I have now works perfectly if I only have year/years selected. However, as soon as month is selected it goes haywire since production number is reduced based on month and week. How do I calculate total production for selected years between Jan 1st of lowest year selected and last day of highest year selected. I have tried solution presented as following in another thread, but it does not work when month/week is selected. TIA. 

 

Measure = 
CALCULATE (
    SUM ( ValueTable[Value] ),
    FILTER (
        ValueTable,
        ValueTable[Date] >= MIN( PeriodTable[StartDate] )
            && ValueTable[Date] <= MAX ( PeriodTable[EndDate] )
    )
)

 

 
1 ACCEPTED SOLUTION
FarihaImami
Frequent Visitor

Got some help from internal Power BI. Created two columns in the date table: 

 

StartOfYearDATE(YEAR([Datetable]),01,01)

EndOfYear = IF(YEAR([Date])<YEAR(Today()), DATE(YEAR([Date]),12,31), TODAY()-1)

 

I then created a new measure as following:

 

Total Production for the year =

var beg = MIN('Datetable'[StartOfYear])
var eoy = MIN('Datetable'[EndOfYear])
return CALCULATE('Production'[Total Production],FILTER(ALL('Datetable'),'Datetable'[StartOfYear] = beg && 'Datetable'[EndOfYear] = eoy && 'Datetable'[Plant] in VALUES(Planttable[Plant])))
 
The last filter is to capture plant slicer on the page. Once this measure was created, I divided this by 'number of daye selected' measure from my first message on this thread. 

View solution in original post

11 REPLIES 11
FarihaImami
Frequent Visitor

Got some help from internal Power BI. Created two columns in the date table: 

 

StartOfYearDATE(YEAR([Datetable]),01,01)

EndOfYear = IF(YEAR([Date])<YEAR(Today()), DATE(YEAR([Date]),12,31), TODAY()-1)

 

I then created a new measure as following:

 

Total Production for the year =

var beg = MIN('Datetable'[StartOfYear])
var eoy = MIN('Datetable'[EndOfYear])
return CALCULATE('Production'[Total Production],FILTER(ALL('Datetable'),'Datetable'[StartOfYear] = beg && 'Datetable'[EndOfYear] = eoy && 'Datetable'[Plant] in VALUES(Planttable[Plant])))
 
The last filter is to capture plant slicer on the page. Once this measure was created, I divided this by 'number of daye selected' measure from my first message on this thread. 
Ashish_Mathur
Super User
Super User

Hi,

Assuming the Year, Month and Week slicers have been created from the DateTable table, try this measure

=calculate(sum(valuetable[value]),datesbetween('datetable'[date],minx(allexcept('datetable','datetable'[year]),'datetable'[date]),maxx(allexcept('datetable','datetable'[year]),'datetable'[date])))

If this measure does not help, then share the download link of your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Asish. Thank you for your reply. However, it did not help. I cannot share the original file due to confidential information, but I have created one as close to actual as possible. You can see the file below. Thank you for your help. 

 

Power BI test file 

You are welcome.  Why is there no Date column on the Production Table?  Please share the revised dataset with a Date column in the Production table.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur I have added the date in production table using LOOKUPVALUE. However, note that the actual file is linked up by "Measure ID" as the example file and Date column does not exist in Production Table. 

 

Power BI test updated with date 

That is not how it should be.  The production table should have an independent Date column.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Sadly it does not. These data are coming from SQL database and Measure ID are what connecting date table to Production table as well as downtime record table. Does this mean I cannot do what I am looking to do? Ultimately I want a YTD daily average production number that is only based on YEAR and does not change with Month/Week/Day selection. 

 

As last resort, I tried setting it up as a separate visual but on the same page and it was still affected by month selection. 

Hi,

You may download my PBI file from here.  I have turned off Interactions between the Month slicer and the table visual.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you Asish. However, this does not help me since on the same table I have other KPIs that does need to interact with Month slicer. So I cannot turn off the interaction. 

 

Looks like this challenge is more difficult than it appears. 

davehus
Memorable Member
Memorable Member

Hi @FarihaImami , 

 

Are you trying to retain the average for year, regardless if month is selected, so basically you do not want a month/week filter applied to this calculation?

 

 

Yes. No month/week filter application to this measure. 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.