Forum Discussion

mmikemcgregor1's avatar
mmikemcgregor1
New Member
3 years ago
Solved

Identifying first rows based on a summed value

Hi all, one more problem. I have a table with a date column, # of hours worked, and our normal price per hour. Usually we charge '$X' per hour but for one client we charge them '$Y' for the first 10 hours of work every month and '$X' for everything after that. 

Should I attempt to do this in DAX or Power Query? How can I isolate the first time entries every month until they aggregate to the 10 hr limit. Do I need something like a conditional column that says at the start of every month charge '$Y' for the first 10 hours and then charge '$X' for anything after that?

Any thoughts would be appreciated 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi  mmikemcgregor1 ,

    Here are the steps you can follow:

    1. In Power query. Add Column – Index Column – From 1.

    2. Create calculated column.

    Rankx =
     RANKX(FILTER(ALL('Table'),
     YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&
     MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))),[Index],,ASC)
    Sum =
    SUMX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&
     MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Rankx]<=EARLIER('Table'[Rankx])),[Work Hours])
    Need to change Rate/Hr =
    IF(
    'Table'[Sum]<=10,"150","Stay at Normal Rate")

    3. Result:

     

    Best Regards,

    Liu Yang

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

5 Replies

  • vanessafvg's avatar
    vanessafvg
    Community Champion

    Little bit difficult to know without seeing your data.

     

    It sounds to me like something you could do in dax, do you have sample data to share?

     

     

    • mmikemcgregor1's avatar
      mmikemcgregor1
      New Member

      Sorry, should have included a sample data set. The table below is how the data appears in our data pull. So I need to reclassify the first 10 hours each month(regardless of who worked them) to $150/hours and the rest of the time in that month stays at the normal rate.

      • mmikemcgregor1's avatar
        mmikemcgregor1
        New Member
        DateTitleWork HoursRate/HrTotal Amt Need to change Rate/Hr
        7/1/2022Manager1300300 150
        7/1/2022Apprentice2200400 150
        7/2/2022Manager43001200 150
        7/2/2022Apprentice1200200 150
        7/3/2022Manager1300300 150
        7/3/2022Apprentice1200200 150
        7/4/2022Manager3300900 Stay at Normal Rate
        7/4/2022Apprentice62001200 Stay at Normal Rate
        7/5/2022Manager1300300 Stay at Normal Rate
        7/5/2022Apprentice2200400 Stay at Normal Rate
        7/6/2022Manager3300900 Stay at Normal Rate
        7/6/2022Apprentice2200400 Stay at Normal Rate
        8/1/2022Manager2300600 150
        8/1/2022Apprentice52001000 150
        8/2/2022Manager3300900 150
        8/2/2022Apprentice4200800 Stay at Normal Rate
        8/3/2022Manager1300300 Stay at Normal Rate
        8/3/2022Apprentice52001000 Stay at Normal Rate
        8/4/2022Manager3300900 Stay at Normal Rate
        8/4/2022Apprentice1200200 Stay at Normal Rate
  • davehus's avatar
    davehus
    Memorable Member

    Hi mmikemcgregor1 ,

     

    See an example below. If you know that the customer is getting a rate for the first 10 hours, then the best thing to do is a base rate calculation less the 10 hours and then those 10 hours at the other rate and add them up. Again as vanessafvg mentioned hard to figure without seeing data. This may help you get started though. 

     

    Hope this helps

     

    Did I help you today? Please accept my solution and hit the Kudos button.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  mmikemcgregor1 ,

    Here are the steps you can follow:

    1. In Power query. Add Column – Index Column – From 1.

    2. Create calculated column.

    Rankx =
     RANKX(FILTER(ALL('Table'),
     YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&
     MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))),[Index],,ASC)
    Sum =
    SUMX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(EARLIER('Table'[Date]))&&
     MONTH('Table'[Date])=MONTH(EARLIER('Table'[Date]))&&'Table'[Rankx]<=EARLIER('Table'[Rankx])),[Work Hours])
    Need to change Rate/Hr =
    IF(
    'Table'[Sum]<=10,"150","Stay at Normal Rate")

    3. Result:

     

    Best Regards,

    Liu Yang

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