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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
powerlight1
Helper I
Helper I

Help with Filtering Using A Separate Table

Hi, I need help with filtering using a separate table and calculating an average based on filtered records.

 

I have a Sales table

Date, Sales

1/11/2024, 1

2/11/2024, 2

3/11/2024, 3

4/11/2024, 4

5/11/2024, 5

6/11/2024, 9

 

and I have a separate "slicer_date[date]" table which I used as my date slicer

Date

1/11/2024

2/11/2024

3/11/2024

4/11/2024

5/11/2024

6/11/2024

 

I have a Filter_measure:

Filter_measure = IF( MAX(SALES[DATE]) = ALLSELECTED(slicer_date[date]).

 

When I select the first 5 days in my date slicer:

powerlight1_0-1756099073141.png

 

I just want to calculate the average of the first 5 days of Sales, ie from 01/11/2025 to 05/11/2024 which should be "3".  But when I put the "Sales" field into a table and change summarization to Average it comes up as "4" because it is averaging across 6 days and not just 5 days.

 

If I only have Average Sales then it is calculating incorrectly:

powerlight1_0-1756100086492.png

but when I include the field "date" it calculates correctly but I do not want to show "date" in the output table:

powerlight1_1-1756100159429.png

 

 

Do you know why the 5 days set in the date slicer is not passing into the table when I don't include "date" in the output?

1 ACCEPTED SOLUTION
Shahid12523
Community Champion
Community Champion

Your slicer table isn’t filtering Sales, so the average uses all 6 days.

 

Fix: Create a measure with TREATAS

 

Avg Sales by Slicer =
CALCULATE(
AVERAGE(Sales[Sales]),
TREATAS(VALUES(slicer_date[Date]), Sales[Date])
)


Now the slicer dates will filter Sales, and the average for 1–5 Nov will return 3.

 

Alternative: just relate slicer_date[Date] → Sales[Date] directly.

Shahed Shaikh

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

As long as the reaulationship between dates is properly set up (Many to One and Single) and the slicer is from the date table, this simple measure should work

Avg = average(Data[Sales])

Hope this helps.


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

I must explain, I can't set up a relationship between my Sales table and my slicer_date table because I have a second slicer_date2 table allowing the user the flexibility to select 2 different sets of dates from 2 different slider_date tables and returning both date period calcuation.

 

powerlight1
Helper I
Helper I

Thanks @Shahid12523 

That worked.  I'm new to PBI so was wondering why didn't the Filter Measure I created and placed in the visual's filter did the job? 

danextian
Super User
Super User

Hi @powerlight1 

What does the measure do? It has an incorrect syntax.

danextian_1-1756112953894.png

 

That aside and even if you use an implicit measure and assuming that there's only one row for each date, the average would still have returned correctly even without the date colum  had there been a relationship betweeen your sales and slicer tables.

 

danextian_2-1756112972461.png

danextian_3-1756112998575.png

 

If there are more than one rows for each date, you will need to create a measure to calculate the daily average

AVERAGEX ( ALLSELECTED ( slicer_date ), CALCULATE ( SUM ( sales[amount] ) ) )

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

@danextian 

the filter measure should be:

Filter_measure = IF( MAX(SALES[DATE]) = ALLSELECTED(slicer_date[date]),1,0).

 

Shahid12523
Community Champion
Community Champion

Your slicer table isn’t filtering Sales, so the average uses all 6 days.

 

Fix: Create a measure with TREATAS

 

Avg Sales by Slicer =
CALCULATE(
AVERAGE(Sales[Sales]),
TREATAS(VALUES(slicer_date[Date]), Sales[Date])
)


Now the slicer dates will filter Sales, and the average for 1–5 Nov will return 3.

 

Alternative: just relate slicer_date[Date] → Sales[Date] directly.

Shahed Shaikh

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.