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
parimal
New Member

Calculating measure with custom filters

I have a data model with 2 tables - DimCustomer and FactTable

DimCustomer has {Customer, Customer Name}

FactTable has {Material, Customer, DataSource, Date, Quantity, Value} 

There are 2 data sources - SourceA, SourceB.

 

I'm trying to get a measure that calculates the Max Date for each Customer from SourceA only. 

 

I wrote a measure formula

Last Date Measure = CALCULATE(MAX(FactTable[Date]),KEEPFILTERS(FactTable[DataSource]="SourceA"))

 

But this doesn't work as expected in all scenarios especially when there is another filter on the report.

 

So I added a calculated column in my DimCustomer Table with the same formula - 

Last Date Col = CALCULATE(MAX(FactTable[Date]),KEEPFILTERS(FactTable[DataSource]="SourceA"))

This one works fine.. Example below .. I have one material selected - the column formula gives correct answer, measure doesn't.

What's the correct way to write this measure formula such that it gives me the expected answer?

 

Capture.PNG

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@parimal 

Create the following measure:

 

measure = calculate(max(table[date]),filter(all(table),sumx(filter(table,earlier(table[customer])=table[customer]),1)),table[Source]="Source A")

 

 

Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@parimal 

Create the following measure:

 

measure = calculate(max(table[date]),filter(all(table),sumx(filter(table,earlier(table[customer])=table[customer]),1)),table[Source]="Source A")

 

 

Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

parimal
New Member

Capture.PNG

this is my fact table for customer 19.. there are 2 rows, and no matter which material i chose, i want the answer to be 30-sep-2019.

 

 

karun_r
Microsoft Employee
Microsoft Employee

Please try this measure and let me know if it works

 

Max Date from SourceA = CALCULATE(MAX(Source[Date]), ALL(FactTable[Material]), DataSource = "SourceA")

 

@parimal add column using following expression.

 

Source A date = 
CALCULATE ( 
    MAX ( Source[Date] ), 
    ALLEXCEPT ( Source, Source[Customer] ), 
    Source[Source] = "Source A" 
)

  Would appreciate Kudos 🙂 if my solution helped. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.