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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
shakirkhanani
Helper I
Helper I

Calculate number of days between milestones

Hi, 

 

I was wondering whether to calculate number of days between two milestones, for example:

 

How many days a store took to achieve their first million in sales, and the second million......

 

I used the following :

 

First Million = CALCULATE(DISTINCTCOUNT(Sales[Date]),Sales[Amount]<=1000000)

 

Result seems to be incorrect

 

Second Million = CALCULATE(DISTINCTCOUNT(Sales[Date]),FILTER(Sales,Sales[Amount]>=1000000 && Sales[Amount]<=2000000)

 

Result only blank rows

 

Capture.PNG

 

 



 

 

 



Any suggestions?

 

 

 

1 ACCEPTED SOLUTION

@shakirkhanani

 

Sample file attached as well

 


Regards
Zubair

Please try my custom visuals

View solution in original post

10 REPLIES 10
v-yuta-msft
Community Support
Community Support

Hi shakirkhanani ,

 

"Result seems to be incorrect"

 

<--- What's the format of date column and your expected value? And could you share a sample file with some dummy data for further analysis?

 

Regards,

Jimmy Tao

Thanking for taking interest.   Please find below the link to the sample file, I have removed the unnecessary columns.

 

https://lattlivcompk-my.sharepoint.com/:x:/g/personal/shakir_khanani_lattliv_com_pk/EeF9wlFqE2xNoce6...

parry2k
Super User
Super User

Are you getting correct result for first million?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

No Sir, its not giving correct answer.

can you share sample dataset for the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@shakirkhanani

 

Please try this MEASURE

 

I assume you have data like this

 

Store CodeDateAmount
PK01Saturday, January 6, 2018259,322
PK01Thursday, January 11, 2018199,957
PK01Thursday, January 25, 2018143,811
PK01Saturday, February 3, 2018121,347
PK01Tuesday, February 6, 2018220,141
PK01Wednesday, February 14, 2018180,620
PK01Friday, February 16, 2018267,602
PK01Friday, March 23, 2018174,671
PK01Saturday, April 7, 2018148,055
PK01Saturday, April 14, 2018125,927
PK01Friday, April 20, 2018273,066
PK01Monday, May 7, 2018154,767
PK01Sunday, June 3, 2018181,640
PK01Saturday, June 23, 2018283,012

 

 

First Million =
VAR temp =
    SUMMARIZE (
        Sales,
        Sales[Date],
        "Cumulative",
        VAR mydate = Sales[Date]
        RETURN
            CALCULATE ( SUM ( Sales[Amount] ), Sales[Date] <= mydate )
    )
VAR DateofAchievemnt =
    MINX ( FILTER ( temp, [Cumulative] > 1000000 ), [Date] )
RETURN
    DATEDIFF ( FIRSTDATE ( Sales[Date] ), DateofAchievemnt, DAY )

 

firstmiilion.png 


Regards
Zubair

Please try my custom visuals

Thanks for the help!, let me try and report back to you soon.

@shakirkhanani

 

And heres the secondmillion formula

 

Second Million =
VAR temp =
    SUMMARIZE (
        Sales,
        Sales[Date],
        "Cumulative",
        VAR mydate = Sales[Date]
        RETURN
            CALCULATE ( SUM ( Sales[Amount] ), Sales[Date] <= mydate )
    )
VAR DateofAchievemnt =
    MINX ( FILTER ( temp, [Cumulative] > 2000000 ), [Date] )
RETURN
    DATEDIFF ( FIRSTDATE ( Sales[Date] ), DateofAchievemnt, DAY ) - [First Million]

Regards
Zubair

Please try my custom visuals

@shakirkhanani

 

Sample file attached as well

 


Regards
Zubair

Please try my custom visuals

Awesome! 

 

Your idea is far better than my work around, which was to calculate running total first and then using Calculate and Filter functions to get required millions.  Although got the same results, but taking running total on larget dataset, really took a toll on my report and slowed it. 

 

Thanks a million yaar!

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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