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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
damit23183
Microsoft Employee
Microsoft Employee

MAX date by group

Hi, 

 

I have below table below,


Table.PNG

 

 

 

 

I am trying to find days between current date and max date by ID. As you can see there are 2 layer below ID.

I am expecting this result,

 

Table.PNG

 

 

 

 

So here No of days is difference between current date and MAX date from each ID.

 

Thanks

1 ACCEPTED SOLUTION

@damit23183 

Ok, I see what you mean now. Try this:

Last Date =
CALCULATE (
    LASTDATE ( FactTable[Date] ),
    ALLEXCEPT (
        FactTable,
        FactTable[ID],
        FactTable[Activity],
        FactTable[Sub Activity]
    )
)

and

Days from today = INT(TODAY() - [Last Date])

 

result.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

18 REPLIES 18
PaulDBrown
Community Champion
Community Champion

@damit23183  

Try:

max date by ID = CALCULATE(LASTDATE(Table [Date], ALLEXCEPT(Table, Table [ID]))

Today - max date by ID = INT(TODAY() - [max date by ID])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi Paul,

 

Thanks for your response but its not working. Let me explain here again what exactly I have.

 

Here is the table I do have currently (this is an example as i can't share data due to privacy);

 

Main Table .PNG

 

 

 

 

 

As you can see above there are multiple layer here up to 3 but in original table there 8 levels.

Now here i would like to calculate no of days between Current date and max of Date column at each level.

 

so for example, for level 1 which at ID column I would like to see the result like this;

Table.PNG

 

 

 

 

Now same goes to Level 2 which is ACTIVITY column in this example so the result should be like this;

Table.PNG

And for Level 3 which Sub-Activity in this example should look like this;

Table.PNG

 

 

 

 

However, at lowest 3-4 levels i am getting what is expected but at top level i am getting like this;

Tab.PNG

Here you can see days are multiplied depending on how many sub activities there.

So at top level its not working but at low level its working.

 

Thanks

@damit23183 

Ok, I see what you mean now. Try this:

Last Date =
CALCULATE (
    LASTDATE ( FactTable[Date] ),
    ALLEXCEPT (
        FactTable,
        FactTable[ID],
        FactTable[Activity],
        FactTable[Sub Activity]
    )
)

and

Days from today = INT(TODAY() - [Last Date])

 

result.JPG

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






OMGosh!!!!!!! I've been fighting Incremental Refreshes over record duplication for "too" long. I can't believe the solution was as easy as a basic "IF MAX() PARTITION OVER() == MAX()" concept. THANK YOU!!!!! You gave me the MAX() PARITION OVER() portion (sorry I use SQL a lot, still learning DAX's oddities / limitations)

Well I'm happy if it helped! Though you lost me with the SQL bits... I know nothing about SQL!!

BTW, if the problem is duplicate rows, can't you just remove them in Power Query?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






The remove duplicates doesn't seem to do any of what I'd expect. It's like it just keeps the first record and drops all after. But you can't "sort" the data so the first record is actually the one you want (not in a way that I could find anyway). And the SQL-Bits are for 2 reasons, one for myself to translate the DAX into a pattern that I live/breath and to help others like me pivoting business logic into DAX / M-Query.

Hi Paul,

I got the solution now.

THank you so much for your help. 

Really appreciate it!

@damit23183 

Great! I was going to say that by creating one single measure, including all the level columns in the ALLEXCEPT expression, you will get the result whether you create individual visuals or a whole matrix including all levels:

Matrix.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi Paul,

 

Thanks for quick response.

You mean i will have to include all levels ID column in LAST DATE calculated Column which you did mention?

or Individual for each ID so for example in this case ID is level 1 that means in when i calculate LAST DATE then only ID should be there in ALL EXCEPT funtion and so on fo other levels?

Ashish_Mathur
Super User
Super User

Hi,

To your matrix/table visual, drag the ID column and write these measures

Max date = max(Data[Date])

Difference = today()-[Max date]

Hope this helps.


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

Hi Ashish,

 

Thank for your response.

 

Well, your solution was the first one i tried but due to hierarchy level in table it did not work.

 

There are multiple level like Level 1 to Level 8 and only one Date column. Further, I need to find MAX date at each level.

 

Thanks

v-luwang-msft
Community Support
Community Support

HI @damit23183 ,

Have you tried as following steps:

Step 1, use the following measure to get the max date for every id :

Measure dax :maxactday = CALCULATE(MAX('Table'[Date]),FILTER(ALL('Table'),'Table'[ID]=MAX('Table'[ID])))

v-luwang-msft_0-1613701326678.png

 

 

Step 2, use the following measure to find days between current date and maxactday:

Measure dax :No Of Days = DATEDIFF('Table'[maxactday],NOW(),DAY)

v-luwang-msft_1-1613701326684.png

 

If you have tried the above steps and  it still no work, can you provide me with your pbix file?Remember to remove the confidential information.

 

Best Regard

Lucien Wang

 

Hi,

WHen i was trying to use this and your previous solution, just found out that Measure is not working when i tried to find days between columns. It always come with memory not enough error message whenever i used measure to find DATEDIFF.

Is there any specific reason why?

 

THanks

Hi,

THanks for checking in and sorry for late response as i got stuck with other work.

I will try this too and let you know but your previous solution work 50%. 

So, let me try and see this solution.

On PBIX i cant share the data as its confidential. I am really sorry for that.

v-luwang-msft
Community Support
Community Support

HI @damit23183 

You could use the following measures:

maxactday = FORMAT(CALCULATE(MAX('Table'[Date].[Date]),FILTER(ALL('Table'),'Table'[ID]=MAX('Table'[ID]))),"YYYY/MM/DD")

No Of Days = DATEDIFF('Table'[maxactday],NOW(),DAY)

 

Then you will get what you want,see the below:

v-luwang-msft_0-1613638529982.png

 

Click  here  to download pbix if you need.

Best Regard

Lucien Wang

 

Hi,

Thanks for your response.

I tried this too but its not working either.

Its giving total days that means in your case if ID "1" has 3 entry so I am getting 45 days in No of Days column when i applied your formula.

 

Thanks

Anonymous
Not applicable

Hi @damit23183 

Create a Column using DAX below.

No Of Days = DATEDIFF(Calculate(MAX('table'[date]),ALLEXCEPT('table','table'[date])),TODAY(),DAY)

OR

No Of Days = DATEDIFF(Calculate(MAX('table'[date]),ALLEXCEPT('table','table'[date])),'table'[Current Date],DAY)

Add +1 at the end if you want to include todays date too.

Hi Pranit,

Thank you for your response.

 

I already tried this solution before but it gave me different result. 

For example, ID no 2 has total 2 entries(If you see Activity and Sub activity) correct.

So, when i tried to apply this formula it gave me no of days  = 22  (11x2).

I only want to show it 11 and thats it.

Is there other solution?

 

Thanks

Helpful resources

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

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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 Solution Authors