Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi there,
I would like to know how you calculate days in between two dates for each year. So you could make a diagram like this :
Solved! Go to Solution.
@Anonymous you can write a meaure like this
Measure =
VAR _fact =
FILTER (
GENERATE ( tbl, DATESBETWEEN ( 'Calendar'[Date], tbl[Begin], tbl[End] ) ),
[Date] <> tbl[Begin]
&& [Date] <> tbl[End]
)
VAR _calendar =
ADDCOLUMNS (
'Calendar',
"count", COUNTX ( FILTER ( _fact, [Date] = EARLIER ( 'Calendar'[Date] ) ), [Date] )
)
RETURN
SUMX ( _calendar, [count] )
Using GENERATE on a fact table seems like a bad idea from a performance perspective. Your _fact variable could potentially be quite an enormous table.
I'd recommend something simpler like this:
DATEDIFF (
MAX ( MIN ( tbl[Begin] ), MIN ( 'Calendar'[Date] ) ),
MIN ( MAX ( tbl[End] ), MAX ( 'Calendar'[Date] ) ),
DAY
)
@Anonymous you can write a meaure like this
Measure =
VAR _fact =
FILTER (
GENERATE ( tbl, DATESBETWEEN ( 'Calendar'[Date], tbl[Begin], tbl[End] ) ),
[Date] <> tbl[Begin]
&& [Date] <> tbl[End]
)
VAR _calendar =
ADDCOLUMNS (
'Calendar',
"count", COUNTX ( FILTER ( _fact, [Date] = EARLIER ( 'Calendar'[Date] ) ), [Date] )
)
RETURN
SUMX ( _calendar, [count] )
The measure is perfect in a diagram but when a switch the same measure in a table or matrix an error occurred:
Can anyone help me with this issue?
Using GENERATE on a fact table seems like a bad idea from a performance perspective. Your _fact variable could potentially be quite an enormous table.
I'd recommend something simpler like this:
DATEDIFF (
MAX ( MIN ( tbl[Begin] ), MIN ( 'Calendar'[Date] ) ),
MIN ( MAX ( tbl[End] ), MAX ( 'Calendar'[Date] ) ),
DAY
)
The measure is perfect in a diagram but when a switch the same measure in a table or matrix an error occurred:
Can anyone help me with this issue?
Please post the full DAX code you're using for this measure. I can't think of a way the DAX I suggested would give this error, so I'm assuming there are some extra bits.
👏
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
18 | |
7 | |
6 | |
5 | |
5 |
User | Count |
---|---|
24 | |
10 | |
10 | |
9 | |
7 |