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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
pmoore
Frequent Visitor

DAX Help for multiple layer filtering

Hello,

 

I've been trying to find an answer for a couple of days but still don't have a good enough grasp on DAX to get the formula to work.  So, I'm trying to display in a table that has the last 30 days, an average for each day of the week, filtered by a dynamic date range.  So, for example, my last 30 days would be 3/5-4/3/2018.  For each day, I have a distinct total of encounters.  I want to compare that number to an average for the specific Day of the Week (so, for 4/3, an average for Tuesdays).  However, I want to limit the range of dates evaluated for the average to let's say between TODAY()-60 to TODAY()-30.  Also important to note that I don't want to lose any filters on the page (for example, Practice/Facility).

 

The table I'm using is the following: DateKey, MonthName, DayofMonth, DayName, Year, then the calculations that I need.  

I've got the formula to work for just diplaying the total of all days for that Day of the week (I can figure out the average from there):

Count Enc Total Day of Week = CALCULATE(DISTINCTCOUNT('ChargeDetailfact'[EncID]), ALLEXCEPT('Date Of Service','Date Of Service'[DayName])).  I also have measures that are used elsewhere that calculate the totals based on the range but those don't work in this table as they repeat the total all the way down.  I'm struggling to add the filter of the date range into the same formula I mentioned above, without losing ALLEXCEPT filter.

 

Any help would be appreciated!

Thanks,

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

Sample/example data please. And also what the expected output from that sample data would be.

 

Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Here's some sample data from Date table and the Fact Table and the desired result.  I'm using a simplified result where I want to see 10 previous days but the formula I'm looking for would calculate the total and average (distinct count of Encounter) based on the time period of Today -15 days to Today -5 days.  I included EntityID and LocationID as indications of filters used on the report but used LocationID 2 for my results. 

Just a note that the data would actually have much older dates of service as well and if I use ALL filter (enumerating columns without DayName), I get the average for that day back to the beginning of time.  However, the goal is to calculate the average for each specific Day of the week, within a certain date range and that range being different than what's included on the visual.

There is a many to one relationship:

ChargeDetailfact to Date

ChargeDetailfact to Location

ChargeDetailfact to Entity

 

Result actually displayed on the report:

DateDayofMonthYearDateKeyDayNameDistinct Count of EncTotal Today-15 to Today-5Avg Today-15 to Today-5
4/4/20184201820180404Wednesday163
4/3/20183201820180403Tuesday242
4/2/20182201820180402Monday311
4/1/20181201820180401Sunday155
3/31/201831201820180331Saturday 22
3/30/201830201820180330Friday100
3/29/201829201820180329Thursday152.5
3/28/201828201820180328Wednesday463
3/27/201827201820180327Tuesday142
3/26/201826201820180326Monday111

 

Full set of results if the filter on the report didn't limit the visual to the last 10 days (Goes out to Today -15 days):

DateDayofMonthYearDateKeyDayNameDistinct Count of EncTotal Today-15 to Today-5Avg Today-15 to Today-5
4/4/20184201820180404Wednesday163
4/3/20183201820180403Tuesday242
4/2/20182201820180402Monday311
4/1/20181201820180401Sunday155
3/31/201831201820180331Saturday 22
3/30/201830201820180330Friday100
3/29/201829201820180329Thursday152.5
3/28/201828201820180328Wednesday463
3/27/201827201820180327Tuesday142
3/26/201826201820180326Monday111
3/25/201825201820180325Sunday555
3/24/201824201820180324Saturday222
3/23/201823201820180323Friday 00
3/22/201822201820180322Thursday452.5
3/21/201821201820180321Wednesday263
3/20/201820201820180320Tuesday342

 

Fact Table (ChargeDetailfact):

pk_DetailDateOfSvcEncIDEntityIDLocationID
120180320121
120180320221
120180320322
120180320322
120180320422
120180320522
120180321621
120180321722
120180321822
120180322922
1201803221022
1201803221122
1201803221222
1201803231321
1201803231421
1201803241522
1201803241622
1201803241522
1201803241622
1201803251721
1201803251822
1201803251822
1201803251922
1201803252022
1201803252122
1201803252222
1201803262322
1201803262322
1201803272422
1201803282521
1201803282621
1201803282722
1201803282822
1201803282922
1201803283022
1201803293122
1201803293122
1201803293121
1201803303221
1201803303222
1201803313321
1201803313421
1201804013521
1201804013521
1201804013622
1201804013622
1201804023722
1201804023822
1201804023922
1201804034021
1201804034122
1201804034222
1201804044322

 

Date Table:

DateKeyDateDayofMonthYearMonthDayName
201803203/20/201820201803Tuesday
201803213/21/201821201803Wednesday
201803223/22/201822201803Thursday
201803233/23/201823201803Friday
201803243/24/201824201803Saturday
201803253/25/201825201803Sunday
201803263/26/201826201803Monday
201803273/27/201827201803Tuesday
201803283/28/201828201803Wednesday
201803293/29/201829201803Thursday
201803303/30/201830201803Friday
201803313/31/201831201803Saturday
201804014/1/20181201804Sunday
201804024/2/20182201804Monday
201804034/3/20183201804Tuesday
201804044/4/20184201804

Wednesday

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.