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
Anonymous
Not applicable

Need a measure to work out most current date and subtract that from a DAX Measure

Hi Experts

 

I have two tables as shown below (made up data)  Table B is the FACT table and Table A has Complaint Dates and ID's. The two tables are linked via the ID column.

 

Here is the scenario. If there is a ID match between Table B and A then

1. Find the most current date for ID 1 its 26/09/2020 and for ID 4 its 16/09/2020. Then i want to be able to subtract this from the following dAX measure

DDM Activated = CALCULATE(
COUNTROWS('Table B),
'Table'[Dept] in {"A","B","C"})
 
Table A
ID    Ref     Date
1      aaa    16.09.2020
 
1      sds     26.09.2020
2      sds     01.09.2020
3      dfs      04.09.2020
4      dsf      04.09.2020
4      bbb     16.09.2020
 
Table B
ID    Ref     DEPT
1      aaa    A
5      sds    A
6      dfs     B
4      dsf     C
 
Relationship Between Table A and B is many to many based on ID column (in real tables)
 
Currently this measure gives me a count of 4 but i want to show 2 as i have two id matchs from table a for Id 1 and 4 as the customer has logged a complaint and i want to exclude this from final result.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

You can create a measure as below:

DDM Activated =
CALCULATE (
    DISTINCTCOUNT ( 'B'[ID] ),
    FILTER ( 'B', 'B'[ID] IN VALUES ( 'A'[ID] ) && 'B'[DEPT] IN { "A", "B", "C" } )
)

Best Regards

Rena

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@Anonymous First, I would avoid many-to-many relationships. You should create a bridge table of unique values for ID and put that between the two tables.

 

Second, I do not understand the finding of the last date thing as I do not understand why that matters in the calculation you are proposing.

 

Third, you don't need CALCULATE. 

 

Try this:

DDM Activated = 
  COUNTROWS(FILTER('Table (28a)','Table (28a)'[Dept] IN {"A","B","C"})) - 
  COUNTROWS(FILTER('Table (28a)','Table (28a)'[ID] IN SELECTCOLUMNS('Table (28)',"ID",[ID])))

PBIX is attached below sig.



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...
Anonymous
Not applicable

Thanks Greg the gods have spoken ill listen. Always appreciate the feedback. Let me test.

Anonymous
Not applicable

Hi @Anonymous ,

You can create a measure as below:

DDM Activated =
CALCULATE (
    DISTINCTCOUNT ( 'B'[ID] ),
    FILTER ( 'B', 'B'[ID] IN VALUES ( 'A'[ID] ) && 'B'[DEPT] IN { "A", "B", "C" } )
)

Best Regards

Rena

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors