Events in Progress - displaying items present between two dates in Power BI / Excel with Power Query

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • 🔽More Info🔽
    If you have a start date and end date but need to calculate how many people or items were present between those dates then you can use Power Query to help with this
    This approach will work in Power BI and Excel
    Source CSV file and Power BI solution is here
    aasolutions.sh...
    I've also done a video using DAX to solve this.
    • DAX and the Start Date...
    You may find the Power Query method means your data takes longer to refresh but there is likely an upside in the speed of your interactions between visuals in the report for your end users.
    Find me on various social media platforms
    wyn.bio.link/

ความคิดเห็น • 81

  • @jakuboprchal236
    @jakuboprchal236 2 ปีที่แล้ว +1

    I've had similar issue with a price lists where each price is valid from-to date and I had to convert the two columns into a day-by-date table. Pitty I haven't seen this video earlier, it would save me a few hours. ;) All your videos are just great. I love them. Thank you, Wyn!

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      Great, thanks for letting me know my videos are helpful Jakub. Greatly appreciated.

  • @roncoderre
    @roncoderre 2 ปีที่แล้ว +3

    Minor suggestion for creating date lists:
    CreateOccupancyDateLists = Table.AddColumn(Source, "OccupancyDates", each {Number.From([CheckIn])..Number.From([CheckOut])}),
    ExpandDateLists = Table.ExpandListColumn(CreateOccupancyDateLists, "OccupancyDates"),
    SetTypeToDate = Table.TransformColumnTypes(ExpandDateLists,{{"OccupancyDates", type date}})

  • @Gazarodd
    @Gazarodd 8 หลายเดือนก่อน +1

    Super useful and clear explenations. Thank you much !

    • @AccessAnalytic
      @AccessAnalytic  8 หลายเดือนก่อน +1

      You’re welcome. Thanks for taking the time to leave a kind comment

  • @050224011
    @050224011 2 ปีที่แล้ว +2

    Looks good, I will test it out. Seems like last weeks Dax might be a little easier, especially if you are working with large tables with big date ranges

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว +1

      It depends, the refresh will take longer but the visual interaction / page load could be quicker

    • @zzota
      @zzota 2 ปีที่แล้ว

      I like to get this sort of calculation done as close to the data as possible, so Power Query would be my first choice.

    • @050224011
      @050224011 2 ปีที่แล้ว

      @@zzota depends on the usercase. I have 500,000 rows of data, with an average of 6 months between the start and end date or each row. Seems like dax would be the way to go, rather than creating millions of extra rows with power query. 9 times out of 10 I’d rather use PQ too but Dax might be the better option for me this time

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      Check this out dobbsondata.co.uk/2022/02/18/data-model-vs-dax/

  • @IvanCortinas_ES
    @IvanCortinas_ES 2 ปีที่แล้ว +1

    Thank you Wyn. Another great resolution!

  • @neo1tom
    @neo1tom 5 หลายเดือนก่อน +1

    thanks wyn this video helps me a lot to fix one of my client issue 😊

    • @AccessAnalytic
      @AccessAnalytic  5 หลายเดือนก่อน

      Great. I appreciate you taking the time to let me know you found it useful

    • @neo1tom
      @neo1tom 5 หลายเดือนก่อน +1

      @@AccessAnalytic If one day you come in Paris, will be a pleasure to meet in person :)

  • @Pataree-b1n
    @Pataree-b1n 11 หลายเดือนก่อน +1

    Awesome Video, thanks a lot! This would really help me out and save me lots of time.

    • @AccessAnalytic
      @AccessAnalytic  11 หลายเดือนก่อน

      I appreciate you taking the time to let me know you found it useful

  • @walterstevens8676
    @walterstevens8676 4 หลายเดือนก่อน +2

    A great example, however I needed the dates in between to skip weekends and holidays. Networkdays does that but is a DAX function. People have written M language equivalents as custom functions but its beyond my skill level to implement them:(

    • @AccessAnalytic
      @AccessAnalytic  4 หลายเดือนก่อน +1

      I’d merge in a table of holidays, then add conditional column called ISWorkingDay, saying if day number of week is 6 or 7 or is holiday then 0 else 1
      Then filter the table to only include 1s

    • @walterstevens8676
      @walterstevens8676 4 หลายเดือนก่อน

      @@AccessAnalytic Ok, I've done that, and filtered my date table down to only the working days. In my other table I have the list of employees together with their sick start days , end dates and hours sick that I want to spread evenly across the working days, so I can eventually add up all the sickleave hours per working day. I've tried creating a measure that includes a filter, so that for every staff member I filter to see if each date is in the range, and a working day, and if so I SUMX it, but I haven't had much success! I think I'm struggling with the syntax, but I could be going about it totally incorrectly. Any help would be appreciated.

    • @AccessAnalytic
      @AccessAnalytic  4 หลายเดือนก่อน +1

      Ah, sorry, merge your holidays onto your fact table after expanding your date list and add the IsWorkingDay there.
      If you want to go down the DAX path then there’s this option th-cam.com/video/YL7H1Rqckb0/w-d-xo.htmlsi=_Kw7ofWKGuglZ5lz

  • @hopefarlow4978
    @hopefarlow4978 11 หลายเดือนก่อน +1

    Thank you for the video!! How would you do this if you wanted to look at number of occupants for each month?

    • @AccessAnalytic
      @AccessAnalytic  11 หลายเดือนก่อน

      I think that's what my chart was showing at 10:30, I then also added date

  • @jamiebrichardson1979
    @jamiebrichardson1979 5 หลายเดือนก่อน +1

    Really helpful video. I would like to use this type of method to find out how many employees I have on shift for every 15 min block of time. Obviously this video is for days. Is there a way to do it for 15 min time intervals?

    • @AccessAnalytic
      @AccessAnalytic  5 หลายเดือนก่อน

      Maybe this approach and your need to incorporate a time table instead of a date table
      DAX and the Start Date End Date Problem aka Events In Progress
      th-cam.com/video/YL7H1Rqckb0/w-d-xo.html
      Time table; th-cam.com/video/-q7v56p192M/w-d-xo.htmlsi=y4P7MZ4BQK1q6em_

  • @skyemegakitty
    @skyemegakitty หลายเดือนก่อน +1

    Very useful!

  • @knorpelmancer
    @knorpelmancer 6 หลายเดือนก่อน +1

    Thank you, exactly what I needed. :)

    • @AccessAnalytic
      @AccessAnalytic  6 หลายเดือนก่อน +1

      I appreciate you taking the time to let me know you found it useful

  • @DSnyd901
    @DSnyd901 ปีที่แล้ว +1

    I think this could be very useful in an aircraft maintenance scheduling scenario where I'm trying to determine the mutual overlap of Aircraft and Mechanics per hour
    I have arrivals and departures of Aircraft and I have start and stops for Mechanics Shifts

  • @teaking1981
    @teaking1981 2 ปีที่แล้ว +1

    Looking at some comments, would list functions and group by break query folding - if not you could employ this method let the database handle the transformation and return a table of distinct dates with the sum and count of guests and rooms simplifying the dax needed and improving powerquery performance.

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว +1

      I’m not sure Glyn, I rarely deal with SQL databases, I’m sure the ideal scenario is to build a view with the data you need

    • @hectorluisgaitan996
      @hectorluisgaitan996 2 ปีที่แล้ว

      @@AccessAnalytic I think it depends on the information that is going to be presented, for example, an age of delinquent customer balances

  • @rbr3552
    @rbr3552 2 ปีที่แล้ว +1

    very useful, thanks, is it possible to do it by month or year instead of days?

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      Yep, you could select the end date and start date columns and Add Column - Subtraction, then right click convert to total years/ months. And use that as a reference in your formula

  • @garyrowe58
    @garyrowe58 หลายเดือนก่อน +1

    Perfect! absolutely what I needed, thank you so much

  • @pragneshmaisuria4656
    @pragneshmaisuria4656 2 ปีที่แล้ว +1

    You are awesome!! Thanks.

  • @JonathanExcels
    @JonathanExcels 2 ปีที่แล้ว +1

    Cool approach

  • @GeertDelmulle
    @GeertDelmulle 2 ปีที่แล้ว +1

    Question: shouldn’t you add 1 to the duration to include the day of check out?

    • @GeertDelmulle
      @GeertDelmulle 2 ปีที่แล้ว +1

      If you start from big data, extending a table like this may become huge. I would try not to increase the cardinality like that.
      My first truly big data challenge some 4 years ago was of exactly this kind: the grain was minutes in a day and the cardinality was millions.
      I solved it in DAX where I also did an extra step of turning the results into a histogram on a day-basis, meaning: calculating the max presence per day and then counting the number of days per presence-bucket in a histogram. That way I calculated the daily occupancy over -say- a year, and we could see how many days a certain occupancy was reached.

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      Interesting Geert, I think there’s use cases for both approaches and the specific scenario will influence the decision

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      I don’t think I’d add the checkout date as the person is not there that day

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      Also, it wil depend on what other data you include in the expanded table. A single column with low cardinality should compress well

    • @GeertDelmulle
      @GeertDelmulle 2 ปีที่แล้ว

      @@AccessAnalytic Wyn, as per your 3rd comment, I may have the wrong definition of ‘cardinality’, the way I learned it it’s the number of records in a table. Do you mean to say that it’s more like the number of distinct records?

  • @thiernoba
    @thiernoba ปีที่แล้ว

    Hi
    Thank you for the video. How to solve the problem with datetime, not Date. What if the difference between the start date and the end date is less than 24 hours( 01/01/2023 00:00:00 to 1/1/2023 23:59:59? If you change it to Date, then start_date = end_date.

    • @AccessAnalytic
      @AccessAnalytic  ปีที่แล้ว

      Possibly add some sort of IF statement to capture that scenario

  • @Bhavik_Khatri
    @Bhavik_Khatri 2 ปีที่แล้ว +1

    Nice video. Could you please post the file too?

    • @AccessAnalytic
      @AccessAnalytic  2 ปีที่แล้ว

      Sure, thanks for the reminder. I've added it in the description and it's here too aasolutions.sharepoint.com/:f:/s/PubliclyAvailableContent/Emq-INXt7R5Cq_L4nHzJD-gBVhueMdTHm7zFpbiifPccOw?e=ySNPwi

  • @ArthurBrita
    @ArthurBrita ปีที่แล้ว +1

    really good, it was what I needed, just did a little change to months instead days

  • @sajadabdulcader5337
    @sajadabdulcader5337 ปีที่แล้ว +1

    Great work - can expand it for hour slots / 15 min slot etc thru rounding in PQ.
    Also if dax concaternatex is used we can find the name of people or any text values be shown like Mr XXX appears in the room number 211 for 30th and 31st of the month and alike. Thanks

  • @ВалеріяТарнавська
    @ВалеріяТарнавська 2 ปีที่แล้ว +1

    It’s just awesome!
    So happy I found your videos!
    *running to check if it helps me to calculate cargo storage cost for each parcel for each day, since parcels quantity, pieces and weight changes from day to day*

  • @tomr9969
    @tomr9969 2 ปีที่แล้ว +1

    Brillant! Thanks for posting! I do agree doing this in PQ may be more efficient than DAX.

  • @user-eu3bw2os5h
    @user-eu3bw2os5h ปีที่แล้ว

    How to know the movement out/in from hotel to another? When I have start and end dates. The problem is that if someone has an end date with hotel X and Start date with the same hotel X, I don't want to count it as checked out

    • @AccessAnalytic
      @AccessAnalytic  ปีที่แล้ว

      I don’t quite understand why someone would have a checkout and then checkin with same hotel. But maybe need to fi some sort of Group By in Power Query and add a flag to exclude certain scenarios

  • @alphamaniac9411
    @alphamaniac9411 2 ปีที่แล้ว +1

    Another great real-world example with a great solution.

  • @HandyPaladin
    @HandyPaladin ปีที่แล้ว +1

    Possibly the most helpful thing you have shared. Thank you.
    Say you wanted to apportion the bill or cost by day. Would you perhaps:
    - calculate the service period in days (difference between start and end)
    - calculate the average cost per day (cost divided by service period)
    - delete columns as per your example.
    - then you can have a measure calculating the cost over the shown date range.

    • @AccessAnalytic
      @AccessAnalytic  ปีที่แล้ว +1

      Cheers. I think If you have a measure for Cost then you can divide it by COUNTROWS of your expanded events in progress table.

    • @HandyPaladin
      @HandyPaladin ปีที่แล้ว +1

      @@AccessAnalytic that is even better. Thanks.

    • @AccessAnalytic
      @AccessAnalytic  ปีที่แล้ว

      No worries

  • @bhaveshgehani1872
    @bhaveshgehani1872 11 หลายเดือนก่อน

    I can't do that in my data. it does not show the right results

    • @AccessAnalytic
      @AccessAnalytic  11 หลายเดือนก่อน

      That’s a shame. Maybe you can post more details to one of the forums such as
      techcommunity.microsoft.com/t5/microsoft-excel/ct-p/Excel_Cat?WT.mc_id=M365-MVP-5002589
      community.powerbi.com/t5/Desktop/bd-p/power-bi-designer
      www.reddit.com/r/PowerBI/s/QnQZVihBnP

  • @MrWish332
    @MrWish332 2 ปีที่แล้ว +1

    Really Very useful, Thank You

  • @clickbisi7016
    @clickbisi7016 ปีที่แล้ว

    Hey in the DAX video you showed the monthly version after the daily solution, do you have one for power query?

    • @AccessAnalytic
      @AccessAnalytic  ปีที่แล้ว

      I think you could just display the daily PQ version at a monthly level if connected to a Calendar table.
      Are you wanting to show the number of people present during the month, or the number of people there at Month End?

  • @GeorgeKlucsarits
    @GeorgeKlucsarits ปีที่แล้ว +1

    Hi Wyn, I just came here from your DAX video on this topic. Very helpful and certainly a different approach. I think the use case is best for those events which have a fairly short duration as in your example. In my case I have some open issues that are over a year old, so the table would expand massively.
    In your DAX example, you account for those events still in progress, i.e. events without an EndDate. For PQ would you add another condition when there is no EndDate, perhaps using Date.From(DateTime.LocalNow()) as the EndDate?

    • @AccessAnalytic
      @AccessAnalytic  ปีที่แล้ว

      Good point on the end date, some sort of approach like you suggest sounds sensible way to go.