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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
umarshehbaz
Frequent Visitor

Need Dax for Start & End Date tabular Representation

Hi,

 

I have following data and I want to represent in below formate. I want to add date filter on top on the basis of transaction date.

Data Avaliable : 

IDLeave TypeRemainingBalanceTransaction Date
2283Annual Leave301/1/2020
2283Annual Leave-12/20/2020
2283Annual Leave-12/21/2020
2283Annual Leave-12/25/2020
2283Annual Leave-14/27/2020
2283Annual Leave-14/28/2020
2283Sick Leave01/1/2020
2283Sick Leave-11/10/2020
2283Sick Leave-13/2/2020
2283Sick Leave-13/9/2020
2283Sick Leave-13/10/2020
2283Sick Leave-13/11/2020
2283Sick Leave-14/6/2020
2283Sick Leave-15/4/2020
2283Sick Leave-15/5/2020
2283Sick Leave-15/6/2020
2283Unpaid Leave01/1/2020

 

Need Output like : 

IDLeave TypeStart DateEnd DateLeavesRemaining Balance
2283Annual Leave1/1/20201/1/20203030
2283Annual Leave2/20/20202/21/2020-228
2283Annual Leave2/25/20202/25/2020-127
2283Annual Leave4/27/20204/28/2020-225
2283Sick Leave1/1/20201/1/202000
2283Sick Leave1/10/20201/10/2020-1-1
2283Sick Leave3/2/20203/2/2020-1-2
2283Sick Leave3/9/20203/11/2020-3-5
2283Sick Leave4/6/20204/6/2020-1-6
2283Sick Leave5/4/20205/6/2020-3-9
2283Unpaid Leave1/1/20201/1/202000

 

 

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

Hi  @umarshehbaz ,

 

You need 4 measures as below:

 

 

_measure = 
var _mindate= MINX(FILTER(ALL('Table'),'Table'[Leave Type]=MAX('Table'[Leave Type])&&'Table'[ID]=MAX('Table'[ID])&&'Table'[Index]<MAX('Table'[Index])&&'Table'[Transaction Date]=MAX('Table'[Transaction Date])-1),'Table'[Transaction Date])
Return
IF(_mindate=BLANK(),MAX('Table'[Transaction Date]),_mindate)
_Startdate = 
var _nextstartdate=CALCULATE([_measure],FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])+1))
Return
IF((MAX('Table'[Transaction Date])=[_measure])&&MAX('Table'[Transaction Date])<>_nextstartdate,'Table'[_measure],IF(_nextstartdate=MAX('Table'[Transaction Date])||_nextstartdate=[_measure],BLANK(),CALCULATE('Table'[_measure],FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1))))
_Leaveremaining = 
var _startdate=[_Startdate] return
IF(ISBLANK(_startdate),BLANK(),CALCULATE(SUM('Table'[RemainingBalance]),FILTER(ALLEXCEPT('Table','Table'[ID],'Table'[Leave Type]),'Table'[Transaction Date]>=_startdate&&'Table'[Transaction Date]<=MAX('Table'[Transaction Date]))))
_Remaining Balance = IF(ISBLANK('Table'[_Startdate]),BLANK(), CALCULATE(SUM('Table'[RemainingBalance]),FILTER(ALL('Table'),'Table'[Transaction Date]>=[_Startdate]&&'Table'[Transaction Date]<=MAX('Table'[Transaction Date])&&'Table'[Leave Type]=MAX('Table'[Leave Type]))))

 

Finally you will see:

Annotation 2020-05-13 130236.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi  @umarshehbaz ,

 

You need 4 measures as below:

 

 

_measure = 
var _mindate= MINX(FILTER(ALL('Table'),'Table'[Leave Type]=MAX('Table'[Leave Type])&&'Table'[ID]=MAX('Table'[ID])&&'Table'[Index]<MAX('Table'[Index])&&'Table'[Transaction Date]=MAX('Table'[Transaction Date])-1),'Table'[Transaction Date])
Return
IF(_mindate=BLANK(),MAX('Table'[Transaction Date]),_mindate)
_Startdate = 
var _nextstartdate=CALCULATE([_measure],FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])+1))
Return
IF((MAX('Table'[Transaction Date])=[_measure])&&MAX('Table'[Transaction Date])<>_nextstartdate,'Table'[_measure],IF(_nextstartdate=MAX('Table'[Transaction Date])||_nextstartdate=[_measure],BLANK(),CALCULATE('Table'[_measure],FILTER(ALL('Table'),'Table'[Index]=MAX('Table'[Index])-1))))
_Leaveremaining = 
var _startdate=[_Startdate] return
IF(ISBLANK(_startdate),BLANK(),CALCULATE(SUM('Table'[RemainingBalance]),FILTER(ALLEXCEPT('Table','Table'[ID],'Table'[Leave Type]),'Table'[Transaction Date]>=_startdate&&'Table'[Transaction Date]<=MAX('Table'[Transaction Date]))))
_Remaining Balance = IF(ISBLANK('Table'[_Startdate]),BLANK(), CALCULATE(SUM('Table'[RemainingBalance]),FILTER(ALL('Table'),'Table'[Transaction Date]>=[_Startdate]&&'Table'[Transaction Date]<=MAX('Table'[Transaction Date])&&'Table'[Leave Type]=MAX('Table'[Leave Type]))))

 

Finally you will see:

Annotation 2020-05-13 130236.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User

@umarshehbaz , Sontion, before leave dates are combined

https://www.dropbox.com/s/i2wzkmvb7g31job/leaveDates.pbix?dl=0

 

Checking on combining leave dates

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Balance should be merged and end date as well please check 

 

 

Capture.PNG

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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