Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.
Hi all,
so I am pretty close to what I need to do but just stuck on this last part. Ok, so I have two columns from SQL, one is a 'start date' and one is an 'end date'. Format is datetime. I used query editor and created a new calculated column that did a date diff in days. Worked fine. Every day between dates is accurate except for one, and this is a repeating pattern. It is always wrong on the latest date for a given line item. That is because in our warehouse, we denote record history with the latest having an end date '12/31/9999.
As you can see from the picture, DAX is counting the duration between the last record (start date is correct) but it's calculating to the above date. What I want to do is instead say for the most recent record, in only this instance calculate days diff by subtracting 'today' from 'start date'
my logic is essentially this: for every record except the latest, do X and for the latest do Y. Also, how do I make it so 'day' count is only business days.
Solved! Go to Solution.
Hi,
my solution:
DATEDIFF =
VAR _varstart = maxx(Tabelle11,Tabelle11[Start])
VAR _varend = maxx(Tabelle11,Tabelle11[End])
VAR _varmaxstart = maxx(ALLSELECTED(Tabelle11),Tabelle11[Start])
RETURN
IF(_varmaxstart=_varstart,DATEDIFF(_varstart,TODAY(),DAY),DATEDIFF(_varstart,_varend,DAY))
Proud to be a Super User!
this worked great!
Hi,
my solution:
DATEDIFF =
VAR _varstart = maxx(Tabelle11,Tabelle11[Start])
VAR _varend = maxx(Tabelle11,Tabelle11[End])
VAR _varmaxstart = maxx(ALLSELECTED(Tabelle11),Tabelle11[Start])
RETURN
IF(_varmaxstart=_varstart,DATEDIFF(_varstart,TODAY(),DAY),DATEDIFF(_varstart,_varend,DAY))
Proud to be a Super User!
User | Count |
---|---|
15 | |
11 | |
6 | |
6 | |
5 |
User | Count |
---|---|
29 | |
17 | |
11 | |
7 | |
5 |