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
kamalbandam
Helper III
Helper III

Sort as per date column in measure

Hi

 

I have a table as following:

DateNo of DaysType

12-Nov-2020

12A
30-Jan-20215B
4-Apr-20208C

5-May-2021

2S
6-Aug-202122A

 

 

Now, I need to sort the date column and calculate the sum of days before Type S from Type column. I have tried but I am not getting how to write a DAX. Any h

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @kamalbandam 

Try to create a measure like this:

Measure = 
var _date_S=CALCULATE(MIN('Table'[Date]),FILTER(ALL('Table'),'Table'[Name]=MAX('Table'[Name])&&'Table'[Type]="S"))
var _sum=CALCULATE(SUM('Table'[No of Days]),FILTER(ALL('Table'),'Table'[Name]=MAX('Table'[Name])&&'Table'[Date]<_date_S&&'Table'[Date]<=MAX('Table'[Date])))

return _sum

 

Result:

vangzhengmsft_0-1638412345970.png

Please refer to the attachment below for details. Hope this helps.

 

 

 

Best Regards,
Community Support Team _ Zeon 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

6 REPLIES 6
v-angzheng-msft
Community Support
Community Support

Hi, @kamalbandam 

Try to create a measure like this:

Measure = 
var _date_S=CALCULATE(MIN('Table'[Date]),FILTER(ALL('Table'),'Table'[Name]=MAX('Table'[Name])&&'Table'[Type]="S"))
var _sum=CALCULATE(SUM('Table'[No of Days]),FILTER(ALL('Table'),'Table'[Name]=MAX('Table'[Name])&&'Table'[Date]<_date_S&&'Table'[Date]<=MAX('Table'[Date])))

return _sum

 

Result:

vangzhengmsft_0-1638412345970.png

Please refer to the attachment below for details. Hope this helps.

 

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

NidhiBhusari
Helper IV
Helper IV

Hi @kamalbandam ,

NidhiBhusari_0-1638170699233.png

Try using the DAX in screenshot.

Hi @NidhiBhusari 

Thanks for answering but I have some other rows and  also where I need to take for a particular record of a person as shown below:

 

DateNo of DaysTypeName

12-Nov-2020

12AMark
30-Jan-20215BMark
4-Apr-20208CMark

5-May-2021

2SMark
6-Aug-202122AMark
31-Dec-202021CJohn
26-Jan-202115SJohn
3-Mar-20214AJohn

 

Now, I need to get the result as Mark - 25 No of days & John - 21 No of days.

Sorry for the incomplete info.

Thanks in Advance

@kamalbandam Do you still want to use this condition - Now, I need to sort the date column and calculate the sum of days before Type S from Type column. I have tried but I am not getting how to write a DAX.

@kamalbandam I have assigned ID to each row and then created two measures as shown in below attached screenshots. 

NidhiBhusari_2-1638256018833.png

 




NidhiBhusari_0-1638255967047.pngNidhiBhusari_1-1638255982513.png

 

but it is static where you keep the index number as you know it but we need to do it dynamically

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.