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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
V-pazhen-msft
Community Support
Community Support

@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
V-pazhen-msft
Community Support
Community Support

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

 

 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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