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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
WrxFlo
Frequent Visitor

Calculate difference between dates based on Month slicer

Hi,

 

I have columns that show rental start and end dates for each serial number

I need to add a month slicer that shows days on rent for month selected.

So for example if I select May, PXT2180 will show 0. PXT1358 will show 16. PXT1328 will show 7.

if I select June, PXT2180 will show 30. PXT1358 will show 30. PXT1328 will show 0.

 

thanks

Tim 

 

 pbi.jpg

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @WrxFlo ,

 

I suggest you to try this code to create a measure to calculate date differences.

Measure = 
VAR _LIST = VALUES(DimDate[Date])
VAR _MINDATE = MIN(DimDate[Date])
VAR _MAXDATE = MAX(DimDate[Date])
VAR _ADDDIFF = ADDCOLUMNS('Table',"DateDiff",IF('Table'[Start Date] IN _LIST, DATEDIFF('Table'[Start Date],IF('Table'[End Date] in _LIST,'Table'[End Date], _MAXDATE),DAY),IF('Table'[Start Date]<=_MAXDATE&& 'Table'[End Date] = BLANK(),DATEDIFF(_MINDATE,_MAXDATE,DAY),0)))
VAR _SUMMARIZE = SUMMARIZE('Table',[Serial #],"DATEDIFF",IF( SUMX(FILTER(_ADDDIFF,[Serial #] = EARLIER('Table'[Serial #])),[DateDiff])=0,0,SUMX(FILTER(_ADDDIFF,[Serial #] = EARLIER('Table'[Serial #])),[DateDiff])+1))
RETURN
SUMX(_SUMMARIZE,[DATEDIFF])

Result is as below.

RicoZhou_0-1655174705387.png

RicoZhou_1-1655174714776.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @WrxFlo ,

 

I suggest you to try this code to create a measure to calculate date differences.

Measure = 
VAR _LIST = VALUES(DimDate[Date])
VAR _MINDATE = MIN(DimDate[Date])
VAR _MAXDATE = MAX(DimDate[Date])
VAR _ADDDIFF = ADDCOLUMNS('Table',"DateDiff",IF('Table'[Start Date] IN _LIST, DATEDIFF('Table'[Start Date],IF('Table'[End Date] in _LIST,'Table'[End Date], _MAXDATE),DAY),IF('Table'[Start Date]<=_MAXDATE&& 'Table'[End Date] = BLANK(),DATEDIFF(_MINDATE,_MAXDATE,DAY),0)))
VAR _SUMMARIZE = SUMMARIZE('Table',[Serial #],"DATEDIFF",IF( SUMX(FILTER(_ADDDIFF,[Serial #] = EARLIER('Table'[Serial #])),[DateDiff])=0,0,SUMX(FILTER(_ADDDIFF,[Serial #] = EARLIER('Table'[Serial #])),[DateDiff])+1))
RETURN
SUMX(_SUMMARIZE,[DATEDIFF])

Result is as below.

RicoZhou_0-1655174705387.png

RicoZhou_1-1655174714776.png

 

Best Regards,
Rico Zhou

 

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

 

 

Thanks Rico Zhou. 

NickolajJessen
Solution Sage
Solution Sage

NickolajJessen_0-1654682102552.png

you might need to add a day deping on how you want to count the number of days

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.