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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
BBart
New Member

How to use value from filter in var when summarize a table

I have a table 'Blad1':

MPCUnitdayCostPrice
1084STK202110100.39
1180STK202110100.06
1220NET202110101.65
10841084202109220.34
11801180202109220.06
12201220202109221.65
10841084202109010.30
11801180202109010.07
12201220202109011.65

 

Then I devrived two tables from is which I will use as filters in order to dynamically compare two periods:

 

Date1 = DISTINCT(Blad1[day])
Date2 = DISTINCT(Blad1[day])
 
Then I want to use these filters to create a New Table as follows (without success):
 
New_Table =
VAR CurrentDate = CALCULATE(MAX(Blad1[day]),FILTER(Blad1, Blad1[day]=SELECTEDVALUE(Date1[day])))
VAR PreviousDate = CALCULATE(MAX(Blad1[day]),FILTER(Blad1, Blad1[day]=SELECTEDVALUE(Date2[day])))
RETURN
SUMMARIZE(
Blad1,
Blad1[MPC],Blad1[Unit],
"CurrentCostPrice", CALCULATE(AVERAGE(Blad1[CostPrice]),FILTER(Blad1, Blad1[day] = CurrentDate)),
"PreviousCostPrice", CALCULATE(AVERAGE(Blad1[CostPrice]),FILTER(Blad1, Blad1[day] = PreviousDate))
)
 
My expected output (filtering Date1[day]= 20211010 and Date2[day]=20210901) is:
MPCUnitCurrentCostPricePreviousCostPrice
1084STK0.390.30
1180STK0.060.07
1220NET1.651.65
 
Does anybody know how I can use these filtered values as VAR in the New_Table formula?
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @BBart 

 

Calculated tables are populated when they are created or when you refresh the whole model. They cannot be dynamically changed by slicers or filters according to user interactions. To achieve your expected result, you need to create measures which can be affected by slicers and use a table visual to show their value in the report. 

 

Create measures 

CurrentCostPrice = 
VAR CurrentDate = SELECTEDVALUE(Date1[day],MAX(Date1[day]))
RETURN
CALCULATE(AVERAGE(Blad1[CostPrice]),ALL(Blad1[day]),Blad1[day] = CurrentDate)
PreviousCostPrice = 
VAR PreviousDate = SELECTEDVALUE(Date2[day],MAX(Date2[day]))
RETURN
CALCULATE(AVERAGE(Blad1[CostPrice]),ALL(Blad1[day]), Blad1[day] = PreviousDate)

21121605.jpg

You can download the attachment to see details. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @BBart 

 

Calculated tables are populated when they are created or when you refresh the whole model. They cannot be dynamically changed by slicers or filters according to user interactions. To achieve your expected result, you need to create measures which can be affected by slicers and use a table visual to show their value in the report. 

 

Create measures 

CurrentCostPrice = 
VAR CurrentDate = SELECTEDVALUE(Date1[day],MAX(Date1[day]))
RETURN
CALCULATE(AVERAGE(Blad1[CostPrice]),ALL(Blad1[day]),Blad1[day] = CurrentDate)
PreviousCostPrice = 
VAR PreviousDate = SELECTEDVALUE(Date2[day],MAX(Date2[day]))
RETURN
CALCULATE(AVERAGE(Blad1[CostPrice]),ALL(Blad1[day]), Blad1[day] = PreviousDate)

21121605.jpg

You can download the attachment to see details. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

BBart
New Member

@Greg_Deckler Sorry, I forgot to @ you :). I adjusted my questions and provided sample data and my expected outcome.. 

Greg_Deckler
Super User
Super User

@BBart Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, 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

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

I added some details. Hope this helps 🙂

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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