0

I created a calculated table based on start and end dates to check which manager is responsible for a product per date.

Result:
Base table

The financial department uses a four week period to report. So 13 periods per year. (not usable in a date table?)
Product number 8098 gets a different manager on the 23rd of januari this year. So at the start manager C5104 is responsible and at the end of period one (202301) C5107 is responsible. To get one responsible manager per period I'd like to filter the table in such a fashion that I get the numbers from the last date in a period. After filtering I don't need the [date] field anymore.

I hope I'm just missing something basic like the 'ELLEXCEPT' But I'm lost...

DISTINCT gives:
Condensed table

One row too many. I'd like to lose the row: 8098, C5104, 202301. To keep only rows showing the manager per product at the end of a period.

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
ecrins
  • 3
  • 1
  • 6
  • Do you need the record you want to remove in other analyses? If not, we can create a solution using Power BI Query Editor – Aseel Al-Laham Feb 19 '23 at 16:22
  • I don't need that record in this calculated table. – ecrins Feb 19 '23 at 16:51
  • Can you share the original data structure you used in your calculated table? – Aseel Al-Laham Feb 19 '23 at 17:01
  • 1
    Hi the structure of the table used to calculate the firts table (With manager code per date) has these fields: [Product],[Start date manager],[End date manager],[manager],[some extra fields] I used DATESBETWEEN to check for the responsible manager for a product per date. [Start date...] is always filled. [End date...] can be empty -> period is still active For one product there's a maximum of one day overlap for the responsible manager (the date that is [End date...] for the one manager =[Start date] for the next responsible manager. – ecrins Feb 20 '23 at 07:15

1 Answers1

0

First, thank you for sharing the original structure; it immensely helped.

I have two suggested solutions using Power Query:

  1. Will remove all previous owners for a project if that project was handed over to another manager in the same period (which, according to your data, is equal to Year Month combination) using Power Query.
  2. Will remove all previous owners for a project if that project was handed over to another manager.

After that, you can create your original calculation for your needed report.

I created test data on an excel sheet to use in my steps, as shown in the image below. Test Data

Steps to follow:

  1. You need to add a column on your original table that will handle the null values in the End date manager column by adding a custom column named EndDate Function Parameter; the formula is:

    = if [End date manager] = null then DateTime.Date(DateTime.LocalNow()) else [End date manager]
    
  2. You need to create two referenced tables from your original table. Call them ProductManagerEndDate and ProductManagerStartEndDate

  3. Disable load for ProductManagerEndDate and keep these columns only: Product, Manager, and EndDate Function Parameter, as shown in the image below. ProductManagerEndDate Data

  4. For ProductManagerStartEndDate, keep these columns only: Product, Manager, StartDate, EndDate, and EndDate Function Parameter, as shown in the image below. ProductManagerStartEndDate

Please name the added column in step one and the table names in step 2 precisely what I wrote because there are used in the Custome function you will create next :).

  1. The custom functions code for:
  • Solution one:

Function name: Count the number of Handoverd Projects record in same period

let
Source = (product as number ,p_date as date) => let
    Source = ProductManagerEndDate,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Product] = product)),
    #"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each Date.Year([EndDate Function Parameter])  = Date.Year(p_date)  and
                                                                Date.Month([EndDate Function Parameter]) = Date.Month(p_date) and
                                                                Date.Day([EndDate Function Parameter]) >= Date.Day(p_date) 
                                        ),
    #"Row Count" = Table.RowCount(#"Filtered Rows1")
in
    #"Row Count"
in
Source
  • Solution two:

Function name: Count the number of Handoverd Projects

let
Source = (product as number ,p_date as date) => let
    Source = ProductManagerEndDate,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Product] = product)),
    #"Filtered Rows1" = Table.SelectRows(#"Filtered Rows", each [EndDate Function Parameter] >= p_date),
    #"Row Count" = Table.RowCount(#"Filtered Rows1")
in
    #"Row Count"
in
Source

If I understand your requirement correctly, you will go with solution one, so the following steps would depend on solution one. If you need the second solution, you only need to invoke the second solution Custome function instead of the first one.

  1. Now, you need to go to the ProductManagerStartEndDate table, and from Add Column tab, you need to choose Invoke Custom Function and populate the data for the popped-out window, as shown in the image below. Invoke Custom Function

  2. Filter the column {Count the number of Projects} or whatever name you gave in step six to be less than 2.

  3. Finally, you keep the Product, Manager, StartDate, and EndDate columns in the ProductManagerStartEndDate table then you can create your original calculation for your needed report.

I hope I helped in a way; if so, please mark this as an answer and vote for it :)

  • 1
    Thank you. I can follow your train of thought and I got a result similar to what you show here. I'm not sure yet if this is the result I'm looking for, but I'll try and see where this leads to. I also tried one single measure that looks promising. It gives a result where you can folow the product per period like breadcrums via the last responsible manager in that period. (How do I upload images in comments?) – ecrins Feb 21 '23 at 14:46
  • I don’t think comments allow image upload, but the important thing is as you said the thought it self if , good luck and if you can accomplish it with dax i hope that you will share it as an answer to your question. – Aseel Al-Laham Feb 21 '23 at 15:07
  • Manager datum = VAR CurrentDate = MAX ( _Datumtabel[Datum] ) RETURN CALCULATE ( COUNTX ( 'P_mngr', IF ( AND ( 'P_mngr'[Date start] <= CurrentDate, OR ( 'P_mngr'[Date end] >= CurrentDate, ISBLANK ( 'P_mngr'[Date end] ) ) ), 1 ) ), CROSSFILTER ( _Datumtabel[Datum], 'P_mngr'[Date end], NONE ) ) – ecrins Feb 22 '23 at 08:46
  • The above DAX helped alot. – ecrins Feb 22 '23 at 08:47
  • I now realise that I focussed to much on the date that the manager switched, giving two managers on one date (the orange lines in my example. Your solution omitted that. But I was looking to filter for just the values on the last date (28-2-2023 for 202301) in a period. An then not caring for any othe manager in those four weeks (1-1-2023 -> 28-1-2023). End result: The last manager in a period determins who's the responsible manager for that product in that period. Even if he just started a few days before the end of that period.... – ecrins Feb 22 '23 at 08:51