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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
mchilders56
Frequent Visitor

How to get the number of days between 2 selected dates on a date slicer

I have a date slicer that is pulling from a Database. how do I give a number of days between these days. I need it to be able to put out 92 days for me or whatever the current selected date range is.  I have seen a lot of different things online but cannot seem to get anything to work. the closet I have gotten is the following but it gives me 28 days which is not right.

 

Days Between = DATEDIFF(
                    MIN(PS_TKT_HIST_LIN[BUS_DAT]),
                    MAX(PS_TKT_HIST_LIN[BUS_DAT]),
                    DAY
                    )

 

mchilders56_0-1726869577174.png

 

 

 

6 REPLIES 6
Ritaf1983
Super User
Super User

Hi @mchilders56 
Your formula works accurately, on which visual did you use it and got the wrong result?

Ritaf1983_1-1726891670315.pngRitaf1983_2-1726891700474.png

pbix is attached

If my answer was helpful please give me a Kudos and accept as a Solution.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

So I figure out how to get the actual number and I have it on my screen as a card. However here is where I run into problem is how to use that number. So I have the 92 days and want to use that specific number in a table that is listing out items that also have the last sale date on them. I am trying to show the Days on Hand of supply by doing

CALCULATE(SUM(IM_INV[QTY_ON_HND]) / (SUM(PS_TKT_HIST_LIN[QTY_SOLD])/VALUE([Days Between])))
 
so the value is not pulling the 92 days because of filters I think. so I need the value of Days beween to use the 92 days rather than the 28 days that it thinks from the last sale date of that item.
 
hopefully that makes sense.

Hi @mchilders56 

please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

mchilders56_0-1727192570879.png

 

mchilders56_1-1727192579269.png

 

so I have this line pulling from my DB based on the time frame in the slicer.  sales data for a particular item.

 

I have calculated the number of days between those dates and have outputed them and Max Date and Mindate using:

Days Between = DATEDIFF(
                    MIN(PS_TKT_HIST_LIN[BUS_DAT]),
                    MAX(PS_TKT_HIST_LIN[BUS_DAT]),
                    DAY
                    )
 
so to calculate the days on hand I would take QTY on Hand/ (QTY sold/Days between)
Days on Hand = (SUM(IM_INV[QTY_ON_HND]) / (SUM(PS_TKT_HIST_LIN[QTY_SOLD])/(CALCULATE(VALUE([Days Between]),  ALLEXCEPT(PS_TKT_HIST_LIN, PS_TKT_HIST_LIN[BUS_DAT])))))
 
but my numbers are not working right. I should be getting 61.33 but instead am getting 59.
if I change the date range it gets off even more. it's like it's doing something with the time frame from the maxdate in my slicer till the current date. but I don't know how to handle that part of it.
Anonymous
Not applicable

No offence, guys.

I think the ALLEXCEPT(PS_TKT_HIST_LIN, PS_TKT_HIST_LIN[BUS_DAT]) may effects the wrong reulst.

You could first test the result of below formula to see if it returns the correct days.

CALCULATE (VALUE ( [Days Between] ),ALLEXCEPT ( PS_TKT_HIST_LIN, PS_TKT_HIST_LIN[BUS_DAT] )

Since there is no detailed data to back it up, I can only suggest that you try the following modified measure to see if it can succeed.

Days on Hand =
(
    SUM ( IM_INV[QTY_ON_HND] )
        / (
            SUM ( PS_TKT_HIST_LIN[QTY_SOLD] )
                / (
                    CALCULATE (
                        VALUE ( [Days Between] ),
                        FILTER (
                            ALLSELECTED ( PS_TKT_HIST_LIN ),
                            [BUS_DAT] = MAX ( PS_TKT_HIST_LIN[BUS_DAT] )
                        )
                    )
                )
        )
)

 

Best Regards,

Stephen Tao

 

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

 

marcelsmaglhaes
Super User
Super User

Hey @mchilders56 

Instead of using DATEDIFF, you can directly calculate the difference in days by subtracting the minimum date from the maximum date selected and adding 1 day to include both start and end days.
Days Between =
IF(
ISBLANK(MIN(PS_TKT_HIST_LIN[BUS_DAT])) || ISBLANK(MAX(PS_TKT_HIST_LIN[BUS_DAT])),
BLANK(),
MAX(PS_TKT_HIST_LIN[BUS_DAT]) - MIN(PS_TKT_HIST_LIN[BUS_DAT]) + 1
)


Regards,
Marcel Magalhães
Microsoft Power BI Official Partner
MCT | Certified PL-300 Power BI

If I've helped, don't forget to mark my post as a solution!



Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors